select from another database dynamic query sql server
DECLARE @sql NVARCHAR(1000), @dbName varchar(50),@someValue INT
SET @dbName ='OperationalDB'
SET @sql = 'SELECT top 10 * FROM ' + QUOTENAME(@dbName) + '..Employee'
--EXEC @sql - It will not work
EXEC sp_ExecuteSQL @sql _ It will work
No comments:
Post a Comment