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 2000 Forums
 SQL Server Development (2000)
 while creating a cursor with the query which has top and passing the value of n

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-05-15 : 07:19:41
pranav writes "OS : WIN200
SQL VER : 7

CREATE procedure lngcorl
@cd1 varchar(5),@cd2 varchar(5),@ndays int as
declare @x numeric(18)
declare @strsql varchar(500)
begin
set @strsql = "SELECT sum(cl1) FROM (select [close] as cl1 from prices where code=@cd1 and date in(select top " +cast(@ndays as varchar) + date from prices where code=@cd1 order by [date] desc))tp
declare cur1 cursor local scroll for select @strsql
open cur1
Here it does not execute the actual does not replace the value of ndays oin the query and it the query is not executed

or

set @x = (select @strsql)
In @x instead of the result. I get the entire string strsql
Please help me."

nr
SQLTeam MVY

12543 Posts

Posted - 2003-05-15 : 11:27:00
select @strsql
You are selecting a string so the result will be the string.
You would expect select 'hello' to result in 'hello' wouldn't you?

If you want to execute the striong then look at exec or sp_executesql - both of which can't be used to generate the cursor.

Advice
DON'T USE CURSORS
It's a relational database so use it as such.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -