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)
 I have a question,please help me

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 SQL
Refer this on how to use Dynamic SQL
http://www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-09-10 : 06:09:10
sarants, hereafter ask your question as a new topic

Try this

declare @aa int
Select @aa = count(*) from authors
Select @aa



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-09-10 : 07:06:08
Or this possibly:

USE pubs

declare @aa varchar(50)
set @aa = 'authors'
exec ('select count(*) from ' + @aa)

DECLARE @strSQL varchar(8000)
SELECT @strSQL = 'select count(*) from ' + @aa
PRINT 'DEBUG:EXEC SQL = ' + @strSQL
EXEC (@strSQL)

Kristen
Go to Top of Page
   

- Advertisement -