March 21, 2013 at 8:57 am
-- this works fine
SELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=sql01;Trusted_Connection=yes;', 'SELECT * from syte_APP.DBO.employee') AS a
-- this code gives me error
DECLARE @Cmd VarChar(4000)
SET @CMD = 'SELECT * from syte_APP.DBO.employee'
SELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=sql01;Trusted_Connection=yes;', @cmd ) AS a
-- Msg 102, Level 15, State 1, Line 4
-- Incorrect syntax near '@cmd'
March 21, 2013 at 9:31 am
skb 44459 (3/21/2013)
-- this works fineSELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=sql01;Trusted_Connection=yes;', 'SELECT * from syte_APP.DBO.employee') AS a
-- this code gives me error
DECLARE @Cmd VarChar(4000)
SET @CMD = 'SELECT * from syte_APP.DBO.employee'
SELECT a.* FROM OPENROWSET('SQLNCLI', 'Server=sql01;Trusted_Connection=yes;', @cmd ) AS a
-- Msg 102, Level 15, State 1, Line 4
-- Incorrect syntax near '@cmd'
If you read BoL you will find out that you can only use an object name or a string constant there. You cannot pass a variable into OPENROWSET...
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy