How 开发者_开发技巧can i use a SQLParameter as as the table name and column name?
SELECT * FROM @TableName Where @ColumName=@Value
I get errors when i try to do something like that.
you'd have to use dynamic sql, which is generally not recommended.
Basically, you'd have to treat your sql like a string, append the variable values you want to include in the sql, then use exec sql to execute it.
Dynamic SQL -
declare @TableName as varchar(20)
declare @ColumnName as varchar(20)
declare @Value as varchar(20)
declare @dynsql as varchar(200)
--Set the values before
SET @dynsql='Select * from '+@TableName+'Where '+@ColumnName+'='+@Value
execute(@dynsql)
精彩评论