CREATE PROCEDURE Test
(
@size int
)
AS
select top @size RoomNumber from RoomInfo
GO
我是想查找表RoomInfo中前@size条纪录,但是报错信息是@size附近有语法错误
------解决方案--------------------------------------------------------
CREATE PROCEDURE Test
(
@size int
)
AS
declare @sql varchar(80)
set @sql= 'select top '+ str(@size)+ ' RoomNumber from RoomInfo '
exec(@sql)
GO
------解决方案--------------------------------------------------------
CREATE PROCEDURE Test
(
@size int
)
AS
select top @size RoomNumber from RoomInfo
GO
你这里@size是整型的。所以不能直接和字符串拼接。。
应该:
CREATE PROCEDURE Test
(
@size int
)
AS
declare @sql varchar(8000)
set @sql= 'select top ' + cast(@size as varchar) + ' RoomNumber from RoomInfo '
exec(@sql)
GO