Problem:
The code reads each row and should determine whether it is empty or not.
I want to print out “works” if the column is null. Otherwise, it should not do anything.
Right now it is not working. It is giving me an error that the column does not exist.(the one mentioned in the if statement)
Here is the code.
Code:
DECLARE Employee_Cursor CURSOR FOR
SELECT [Description]
FROM tblSubViews ts
INNER JOIN tblViewSubViewJoin tvs
ON ts.SubViewId = tvs.SubViewId Where tvs.ViewId = 4
OPEN Employee_Cursor
FETCH NEXT FROM Employee_Cursor
WHILE @@FETCH_STATUS = 0
BEGIN
if (Description = null)
begin
print 'works'
end
FETCH NEXT FROM Employee_Cursor
END
CLOSE Employee_Cursor
DEALLOCATE Employee_Cursor
You cannot compare to
NULLusing equals, you mush useID (Description IS NULL)When using cursors it is also necessary to select into a variable:
You would of course need to declare @Description to be of a type appropriate for the column,