I'm having trouble with this query:
SELECT * FROM OPENROWSET( 'SQLNCLI', 'DRIVER={SQL Server};', 'EXEC dbo.sProc1 @ID = ' + @id )
Gives an error:
Incorrect syntax near '+'.
Anyone know why I'm getting this error?
declare @file_stream VARBINARY(MAX) declare @filePath NVARCHAR(128) set @filePath = 'C:\Temp\print4.
In SQL Server, OPENROWSET can read from a data file without loading the data into a target table. This lets you use OPENROWSET with a simple SELECT statement. Important. Azure SQL Database only supports reading from Azure Blob Storage.
The OPENROWSET(BULK...) function allows you to access files in Azure Storage. OPENROWSET function reads content of a remote data source (for example file) and returns the content as a set of rows.
As suggested by Scott , you cannot use expressions in OPENROWSET
.Try creating a dynamic sql to pass the parameters
Declare @ID int Declare @sql nvarchar(max) Set @ID=1 Set @sql='SELECT * FROM OPENROWSET( ''SQLNCLI'', ''DRIVER={SQL Server};'', ''EXEC dbo.usp_SO @ID =' + convert(varchar(10),@ID) + ''')' -- Print @sql Exec(@sql)
OPENROWSET requires string literals, not expressions. It's complaining about the plus sign, becaue it doesn't expect anything more than a string literal and you follewed the string literal with an operator.
See http://msdn.microsoft.com/en-us/library/ms190312.aspx which states:
'query'
Is a string constant sent to and executed by the provider...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With