what is wrong with the following query ??
declare @dbName varchar (50)
declare @fldName varchar (50)
set @dbName ='student';
set @fldName='stID';
declare @gID smallint
set @gID =4;
DEClARE @sqlstr nvarchar(max);
SET @sqlstr = 'SELECT MAX([' + @fldName +'])
FROM [dbo].['+ @dbName +']
WHERE [dbo].['+ @dbName +'].[gID ] = @gID';
EXEC (@sqlstr)
Msg 137, Level 15, State 2, Line 3 Must declare the scalar variable
WHERE [dbo].['+ @dbName +'].[gID ] = ' + CAST(@gID AS VARCHAR(5));