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
 General SQL Server Forums
 New to SQL Server Programming
 Sintax error

Author  Topic 

goranzr85
Starting Member

5 Posts

Posted - 2011-04-18 : 06:07:52
I have error on this:
select * from openquery(loopback,'exec'+
'YuTeam.dbo'+@param4+'')

Incorrect syntax near '+'.

I don't now where is error.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-18 : 06:23:03
you have to put the entire statement in dynamic sql


declare @sql varchar(max),
@query varchar(max)

select @query = 'exec YuTeam.dbo.' + @param4
select @sql = 'select * from openquery(loopback, ''' + @query + ''')'
print @sql -- print out the inspect the statement
exec (@sql) -- execute it



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-04-18 : 09:22:53
But make sure to read this
www.sommarskog.se/dynamic_sql.html

Madhivanan

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

- Advertisement -