all groups > sql server programming > august 2005 >
You're in the

sql server programming

group:

Cursors


Cursors Chandra
8/31/2005 11:51:51 PM
sql server programming: I wrote the following statements..

set @sqlstring = 'select * from employee'

declare cursTemp Cursor for @sqlstring

....

in sql server it is giving error.. what is wrong with this? How can I use
string variable for declaring cursors?

Thanks
Chandra

Re: Cursors Chandra
9/1/2005 12:21:03 AM
Thanks Uri ... it works

[quoted text, click to view]
Re: Cursors Jonathan Chen
9/1/2005 12:25:04 AM
You need a temp table.Just like this.

declare @sqlstring nvarchar(2000)

select * into dbo.# from employees where 1=2
set @sqlstring = 'select * from employees'
insert into # exec (@sqlstring)
declare cursTemp Cursor for select * from #
drop table #
--------------------------------------------------------------
--------------------------------------------------------------
[quoted text, click to view]
RE: Cursors David Portas
9/1/2005 3:06:03 AM
First you should ask yourself if there is a better solution. Cursors are
almost never necessary and are rarely a good idea. Dynamic cursors are
particularly undesirable.

If you want help to find a better way then please give us some more
information. DDL and sample data would help.

--
David Portas
SQL Server MVP
--



[quoted text, click to view]
Re: Cursors Uri Dimant
9/1/2005 9:57:15 AM
Chandra
If I remember well it is called dynamic cursor and I'm sure BOL have some
topics to describe it.

EXEC ('declare cursTemp Cursor for '+@sqlstring)


[quoted text, click to view]

AddThis Social Bookmark Button