Hi, I have written a cursor like bellow :
declare myCursor cursor
for select productID, productName from products
declare @productID int
declare @productName nvarchar(50)
open myCursor
fetch next from myCursor into @productID,@productName
print @productID
print @productName
set @productID=0
set @productName=''
while @@FETCH_STATUS=0
begin
fetch next from myCursor into @productID,@productName
print @productID
print @productName
set @productID=0
set @productName=''
end
close myCursor
deallocate myCursor
now it print the id and name of the product under each other like:
1
Coffee
2
Apple …
But I want to have the id and name of the each product in a same line like:
1 coffee
2 apple …
What can I do? I converted the id into the String and use +’’+ to concat id and name in a same string. But as the ids and names don’t have same lengths, it didn’t have a clean result. Is there any other way to do this?