Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
OpenRowSet
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
OpenRowSet
Miscellaneous
Thread ID:
00584963
Message ID:
00584963
Views:
54
I want to dynamically build the query I send to the OpenRowset function something like this:

declare @datehb datetime
declare @Query varchar(200)

set @datehb = (select max(date) from histobarraCNE3)

set @Query = ('SELECT * FROM RQuant.dbo.histobarrause3 where date> ''' + cast(datepart(yy,@datehb) as varchar(4)) + '-' + cast(datepart(mm,@datehb) as varchar(2)) + '-' + cast(datepart(dd,@datehb) AS varchar(2)) + '''')
--select @query

SELECT * FROM OpenRowset( 'SQLOLEDB', 'xxxx';'xxxxx';'xxxxx', @Query)

When I execute this, I have the error:
Server: Msg 170, Level 15, State 1, Line 16
Line 16: Incorrect syntax near '@Query'.

How can I tell SQL to run my query?
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Next
Reply
Map
View

Click here to load this message in the networking platform