Dynamic SQL with table name as a parameter
问题 I am trying to execute a procedure into which i send the table name and 2 column names as parameters: EXECUTE IMMEDIATE 'select avg(@column1) from @Table1 where REF_D = @column2' into ATTR_AVG; I have tried using the variables in combiations of '@' , ':' , '||' but nothing seems to work. Has anyone used table names as a parameter. there are a few solutions here but for SQL Server 回答1: You can only use bind variables (denoted by colons) for values, not for parts of the structure. You will have