calvinsinger
Programmer
Hello All,
My question has 2 parts. Please help if you can.
Help appreciated
Thanks
Calvin
Part 1
-------
SQL 2000 supports a new data type, table. However I am having trouble using it, when I use it as part of string,
which I execute.
for example
-declare @my_table TABLE (MYID int)
-set @querystring = 'insert into @my_table select MYID where ...)
-exec (@querystring) . This statement fails because of @my_table. it does not recognise the table variable.
where as if i directly do...
insert into @my_table values(1) - This works
One way to solve this problem is to use temporary table,
instead of table variable. But that does not serve my purpose.
Part 2
------
Is there a way one can use a exec with a cursor ? Eventually, I want to be able to create a cursor with a query string, instead of a select statement, but I am unable to do it.
for example we know one can do this..
declare my_crs cursor READ_ONLY for
select * from .....
But what if my select statement is a string. It has to be string because I use optional parametes, and build it dynamically, depending on what parameters are supplied
when the procedure is called
for example, my need is ..
declare @query_string varchar(100)
set @query_string = 'select * from Names where title =''' + @title + ''''
Now, having formed this @query_string, I would like to use this to create a cursor. But since I am using a @query_string, I have to use exec. And it does not appear that one can use a exec with a cursor
My question has 2 parts. Please help if you can.
Help appreciated
Thanks
Calvin
Part 1
-------
SQL 2000 supports a new data type, table. However I am having trouble using it, when I use it as part of string,
which I execute.
for example
-declare @my_table TABLE (MYID int)
-set @querystring = 'insert into @my_table select MYID where ...)
-exec (@querystring) . This statement fails because of @my_table. it does not recognise the table variable.
where as if i directly do...
insert into @my_table values(1) - This works
One way to solve this problem is to use temporary table,
instead of table variable. But that does not serve my purpose.
Part 2
------
Is there a way one can use a exec with a cursor ? Eventually, I want to be able to create a cursor with a query string, instead of a select statement, but I am unable to do it.
for example we know one can do this..
declare my_crs cursor READ_ONLY for
select * from .....
But what if my select statement is a string. It has to be string because I use optional parametes, and build it dynamically, depending on what parameters are supplied
when the procedure is called
for example, my need is ..
declare @query_string varchar(100)
set @query_string = 'select * from Names where title =''' + @title + ''''
Now, having formed this @query_string, I would like to use this to create a cursor. But since I am using a @query_string, I have to use exec. And it does not appear that one can use a exec with a cursor