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 - 2005-09-09 : 07:37:40
|
| ponty writes "hi.i have a question,please help me.i want to create a Stored Procedure like this:when you run it: exec mystoredprocedure(code int,name varchar(10))then,with this statement,stored procedure Create table whi 2 columns,one Code and the other Name" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-09 : 07:46:23
|
| This kind of table creations are not recommended as you need to use Dynamic SQLRefer this on how to use Dynamic SQLhttp://www.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
sarants
Starting Member
1 Post |
Posted - 2005-09-10 : 05:17:24
|
| How to store the result of Dynamic sql in one variable.For example declare @aa varchar(50) set @aa = 'authors' exec ('select count(*) from authors') The result of the Dynamic sql stored in one variable. How can i proceed? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-10 : 06:09:10
|
| sarants, hereafter ask your question as a new topicTry thisdeclare @aa intSelect @aa = count(*) from authorsSelect @aaMadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-09-10 : 07:06:08
|
Or this possibly:USE pubsdeclare @aa varchar(50)set @aa = 'authors'exec ('select count(*) from ' + @aa)DECLARE @strSQL varchar(8000)SELECT @strSQL = 'select count(*) from ' + @aaPRINT 'DEBUG:EXEC SQL = ' + @strSQLEXEC (@strSQL)Kristen |
 |
|
|
|
|
|