I'm using SQL Server 2008. My stored procedure have to pass dynamic database name and store the column value into a variable
ALTER PROCEDURE [dbo].[proc_testproc](@mUserId int)
AS
declare @logCreate BIT;
declare @dbname sysname;
set @dbname = 'finaldb'
exec('SELECT ua.LogCreate AS ' + @logCreate + ' from '+ @dbname
+ 'dbo.User_Access as ua where ua.UserId=' + @mUserId + ')
IF @logCreate = 1
--- Below some insertion happens based on the select query output--
Can anyone help me how to pass dynamic database name and store the value into a variable?