I'm writing a stored procedure that uses DynamicSQL using the
following code:
SET @Get_Role_Numbe r = 'Select @Role_Number = ' + @DatabaseName +
'.dbo.sysusers. uid FROM ' + @DatabaseName + '.dbo.sysusers WHERE ' +
@DatabaseName + '.dbo.sysusers.[name] = ' + @ApplicationRol e
Execute sp_executeSQL @Get_Role_Numbe r, N'@Role_Number int output,
@DatabaseName varchar(50), @ApplicationRol e varchar(50)', @Role_Number
OUTPUT, @DatabaseName, @ApplicationRol e
The column name in the table is "name" and I get a message that there
is no such columnname and it gives the value of the parameter passed
as the column name. Is there any way around this?
following code:
SET @Get_Role_Numbe r = 'Select @Role_Number = ' + @DatabaseName +
'.dbo.sysusers. uid FROM ' + @DatabaseName + '.dbo.sysusers WHERE ' +
@DatabaseName + '.dbo.sysusers.[name] = ' + @ApplicationRol e
Execute sp_executeSQL @Get_Role_Numbe r, N'@Role_Number int output,
@DatabaseName varchar(50), @ApplicationRol e varchar(50)', @Role_Number
OUTPUT, @DatabaseName, @ApplicationRol e
The column name in the table is "name" and I get a message that there
is no such columnname and it gives the value of the parameter passed
as the column name. Is there any way around this?
Comment