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 |
|
rpieszak
Starting Member
11 Posts |
Posted - 2002-02-27 : 14:05:35
|
| What would be the correct syntax for this (I'm getting a syntax error):Select @myVar = Exec(@SQL)The var @SQL is dynamically created and executed and I want @myVar set equal to the result. It's similar to this line:Select @myVar = (Select top 1 myColumn From myTable)but with an Exec() function. Any ideas? Thanks for any help.RyanEdited by - rpieszak on 02/27/2002 14:06:39 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-02-28 : 00:19:02
|
| If you are using Sql 2000. something like this should help youcreate table #t(a int)declare @sql as varchar(300)declare @m intselect @sql='select max(job_id) from jobs'insert into #t exec(@sql)select @m=a from #tdrop table #t--------------------------------------------------------------Edited by - Nazim on 02/28/2002 01:12:59 |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-28 : 04:00:05
|
| Try sp_executesqldeclare @myVar intexec sp_executesql N'select @myVar = (Select top 1 myColumn From myTable)', N'@myVar int output', @myVar outputselect @myVar ==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
rpieszak
Starting Member
11 Posts |
Posted - 2002-02-28 : 13:05:56
|
| Thank you both, your suggestions worked, this is a huge step in what I need to get done. Thanks again! |
 |
|
|
|
|
|