这个存储过程哪有问题?
CREATE PROCEDURE get_count
(@tablename varchar(100))
AS
SELECT COUNT(*) FROM @tablename
GO
报错说 :没声明@tablename
我应该怎么写?
------解决方案--------------------CREATE PROCEDURE get_count
(@tablename varchar(100))
AS
exec( 'SELECT COUNT(*) FROM '+ @tablename )
GO
------解决方案--------------------CREATE PROCEDURE get_count
(@tablename varchar(100))
AS
exec( 'SELECT COUNT(*) FROM '+@tablename)
GO
------解决方案--------------------SQL里面表名、数据库名、索引名、字段名都必须是确认值才能执行
直接写select * from @t是不行的
只能构建一个SQL语句,再用exec