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 2005 Forums
 Transact-SQL (2005)
 query help

Author  Topic 

cognos79
Posting Yak Master

241 Posts

Posted - 2010-01-28 : 13:22:27
I am trying to write multiple statements in a dynamic sql string.


declare @sql1 varchar(max)
declare @sql2 varchar(max)
declare @sql3 varchar(max)
set @sql1 = 'SELECT * into #rd from students'
set @sql2 = 'select * from #rd'

set @sql3 = @sql1 + ' ' + @sql3

exec @sql3.

I get error saying "could not find procedure 'select * into #rd from students......'

how can i achieve this using dynamic sql.



DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-28 : 13:27:13
1. Im sure you meant set @sql3 = @sql1 + ' ' + @sql2

2. to run put it in parenthasis : Exec (@sql3)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-29 : 02:27:05
What is the need of this code?

It can be as simple as

select * from students

Madhivanan

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

- Advertisement -