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 |
|
iswan
Starting Member
28 Posts |
Posted - 2007-06-07 : 03:00:13
|
| The below is correctly executing exec('declare @NumCount int select @NumCount=count(*) from '+@Projectname)But I want to get the output outside the exec. Using this output I process some other function. I don't know how to store output in new variableI need like this, But It is not coming correctlycreate proc trial (@Projectname varchar(512))asdeclare @NumCount intset @NumCount=exec(select count(*) from '+@Projectname)if(@NumCount>1)begin//....(more process)endend |
|
|
bpgupta
Yak Posting Veteran
75 Posts |
Posted - 2007-06-07 : 03:30:14
|
| Can clarify what is variable @projectname |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-07 : 04:22:29
|
| I donno why u want dynamic sql.....butthis will help youdeclare @count intexec('select count(*) from '+ @Projectname)Set @count = @@rowcount@@rowcount will give the no of rows affected by the last statementhere you want count, so take that into some variable after the exec statement.--------------------------------------------------S.Ahamed |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-07 : 04:31:10
|
quote: Originally posted by pbguy I donno why u want dynamic sql.....butthis will help youdeclare @count intexec('select count(*) from '+ @Projectname)Set @count = @@rowcount@@rowcount will give the no of rows affected by the last statementhere you want count, so take that into some variable after the exec statement.--------------------------------------------------S.Ahamed
You will always get 1 for thatThe correct method is using sp_executesqlhttp://www.nigelrivett.net/SQLTsql/sp_executeSQL.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-06-07 : 04:40:00
|
| Sorry man, i did not notice that in the message tabThanks for pointing--------------------------------------------------S.Ahamed |
 |
|
|
iswan
Starting Member
28 Posts |
Posted - 2007-06-08 : 02:26:37
|
| Thanks, I have used the procedure. Now it is working fineIswan |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-08 : 03:24:03
|
| But why do you need to pass table name as parameter?More on dynamic sqlwww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|