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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-05-15 : 07:19:41
|
| pranav writes "OS : WIN200SQL VER : 7CREATE procedure lngcorl@cd1 varchar(5),@cd2 varchar(5),@ndays int asdeclare @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 executedor set @x = (select @strsql)In @x instead of the result. I get the entire string strsqlPlease help me." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-05-15 : 11:27:00
|
| select @strsqlYou 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.AdviceDON'T USE CURSORSIt'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. |
 |
|
|
|
|
|