I'm trying to declare connection as a variable and use it in a query:
DECLARE @connStr VARCHAR(MAX) = 'server=xxxxx'
DECLARE @table VARCHAR(MAX) = 'xxxxx'
BEGIN
DELETE FROM @table;
INSERT @table
SELECT * FROM OPENROWSET(
'SQLNCLI',
@connStr,
'SELECT TOP 10 * from xxxx ORDER BY xxxx DESC'
);
END;
And it results in syntax error.
What's wrong with @connStr? I'm using SQLServer 2012