Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Dynamic SQL - Cursor Problem

Author  Topic 

cheer
Starting Member

1 Post

Posted - 2009-03-15 : 20:57:38
Below is my SQL under a store procedure

declare @ProcessName varchar(30), @SQL varchar(1000)

declare ProductionProcess_Cursor cursor for select ProcessName from RFQ_ProcessPrice order by ProcessSequence
open ProductionProcess_Cursor
fetch next from ProductionProcess_Cursor into @ProcessName
while @@FETCH_STATUS = 0
begin
select @SQL = @SQL + '[' + @ProcessName + ']'
fetch next from ProductionProcess_Cursor into @ProcessName
end
print @SQL
close ProductionProcess_Cursor
deallocate ProductionProcess_Cursor


There isn't any output at the print @SQL. Anyone can advise what is wrong and how to correct

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-03-15 : 21:16:29
Initialize the @SQL variable with a statement like
set @SQL = '';

[As an aside, you can do what you are trying to do without using a cursor. For example, see here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254 ]
Go to Top of Page
   

- Advertisement -