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
 Transact-SQL (2000)
 execeute sql string in stored procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-20 : 10:00:28
wong writes "Hi

I would like to know if i can execute a sql statement in a stored procedure. I know it can be done but i wanted the sql string to be dynamic.
here's what i mean.

Declare @sqlStatement varchar(50)

set @sqlStatement='Select * from table'

Exec @sqlStatament

The reason why i do cose is that i can write a case to compare which tables i m using so that i can dynamically change my sql statement.


Please advise,Thank you"

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2004-04-20 : 10:06:40
Syntax is EXEC(@Statement). It will run in a stored procedure.

Sarah Berger MCSD
Go to Top of Page
   

- Advertisement -