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 |
|
adhik
Yak Posting Veteran
66 Posts |
Posted - 2003-03-28 : 01:10:24
|
| Hi Professionals, I am creating one runtime query in @Stat variable of size varchar(4000) This is of the count(*) type query. e.g. set @Stat = 'Select Count(*) from '+@TableName+' where compId ='+ Cast(compId as varchar(10)) Here @TableName is selected on some conditions in main procedure, i.e. why i need to create run time query. Now i m executing this @Stat using execute sp_executesql in my main procedure. In Books online sp_excutesql gives following Remarks Local cursors or variables in the sp_executesql batch are not visible to the batch calling sp_executesql. but i m not able to get count(*) value in main procedure. How can i achive this.....?? Thanks in advance Adhik Kadam |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-03-28 : 05:29:53
|
| select @tblname = 'mytbl'declare @sql nvarchar(1000) ,@cnt intselect @sql = 'select @cnt = count(*) from ' + @tblnameexec sp_executesql @sql, N'@cnt int', @cnt outalternativelyselect @cnt = select rows from sysindexes where id = object_id(@tblname) and indid in (0,1)seewww.nigelrivett.comsp_executeSQL ==========================================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. |
 |
|
|
adhik
Yak Posting Veteran
66 Posts |
Posted - 2003-03-28 : 05:54:24
|
| Thanks a lot....it works....regardsAdhik |
 |
|
|
|
|
|