Have a problem with using cursors in SQL server enterprise manager

  • Thread starter Thread starter TaeHo Yoo
  • Start date Start date
T

TaeHo Yoo

Have a problem with using cursors in SQL server enterprise manager.
My code sql query is followed
---------------------------------------
DECLARE @element_name varchar(100)
DECLARE elements_cursor CURSOR FOR
SELECT element_name
FROM KB_Element_Ref

OPEN elements_cursor
FETCH NEXT FROM elements_cursor INTO @element_name

WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @element_name
FETCH NEXT FROM elements_cursor INTO @element_name
END

CLOSE elements_cursor
DEALLOCATE elements_cursor
 
Try
<CODE>
DECLARE @element_name varchar(100)
DECLARE elements_cursor CURSOR FOR SELECT element_name FROM
KB_Element_Ref

SELECT COALESCE(element_name,'Null Value') FROM KB_Element_Ref

OPEN elements_cursor
FETCH NEXT FROM elements_cursor INTO @element_name
WHILE @@FETCH_STATUS = 0

BEGIN
PRINT '<<' + @element_name + '>>'
FETCH NEXT FROM elements_cursor INTO @element_name
END

CLOSE elements_cursor
DEALLOCATE elements_cursor
</CODE>

in query analyzer to help check if a zero length string, or null is
being returned.


Rhys Gravell
 
Back
Top