Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cursors 1

Status
Not open for further replies.

imadmarie

Programmer
Nov 14, 2001
14
JO
what im trying to do is to create a cursor in TSQL with a dynamic sql statement not a fixed one, any help ?
 
Make sure you create a GLOBAL CURSOR and the dynamic statement should work.

Declare @sql varchar(1000)

Select @sql=
'DECLARE mycursor CURSOR GLOBAL FOR '+
'SELECT ID, Name From '+ @tablename

Exec(@sql) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
dear tlbroadbent, ur method works fine :)

but i think there's another way using the PREPARE function, do u know about it ?

the method is mentioned in books online, but the problem is that the code is written in SQL for C, and i couldn't manage to make it work in query anylser, any help ?
 
The PREPARE is available in Embedded SQL{/b] not in T-SQL. You can't use PREPARE in SQL Query Analyzer. Unless you are writing C code and want to use Embedded SQL for C you shouldn't use the reference documents for Embedded C. Refer to the Transact-SQL Reference. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
all the sample codes in books online r written in sql for C !!!, where can i use such code ??

and where can i find documentation and sample code for T-SQL ?
 
SQL BOL contains syntax and sample code for T-SQL, VB, SQLDMO, ADO, ODBC, etc. Open SQL BOL and click on the contents tab. Find the "Transact-SQL Reference" for T-SQL syntax and examples. Look in "Building SQL Server Applciations" for examples using various APIs and languages. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top