Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following codes in my SQL Cursor, how can i print out the result based on some conditions? Like for example "if" condition?

SQL
DECLARE @sql NVARCHAR(MAX)
	DECLARE @COUNT INT, @status INT
	DECLARE @cursor CURSOR
		
	
	SET @cursor = CURSOR FOR
	SELECT dbo.CRF_Project.DocStatus
	FROM vsCustomizationRequest.dbo.CRF_Project
	WHERE CustomerID = '1'
	
	OPEN @cursor
	FETCH NEXT
	FROM @cursor into @status
	WHILE @@FETCH_STATUS = 0
	BEGIN
		--HERE
		--IF(@status = 0)
                --SET @COUNT = @COUNT + 1
                --PRINT @COUNT
                --I CANT DISPLAY IT OUT 
		FETCH NEXT
		FROM @cursor into @status
		
	END
	CLOSE @cursor
	DEALLOCATE @cursor
Posted
Comments
CHill60 12-May-14 9:31am    
Why can't you display it?
Sunasara Imdadhusen 27-May-14 7:08am    
Where you want to print?
Suvendu Shekhar Giri 4-Jan-15 3:21am    
Probably, you want to display it in result window. If so, replace PRINT with SELECT. If you want something else, please explain little more about your requirement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900