帮忙看下这个条SQL 语句 谢谢
CREATE PROCEDURE [dbo].[USP_UBSNotice_GetAllByCount]
@count int
AS
declare @strSQL varchar(6000) -- 主语句
set @strSQL= 'select top '+ @count + '* from UBSNotice ' + 'ORDER BY PublishDate DESC '
exec @strSQL
错误 : 在将 varchar 值 'select top ' 转换成数据类型 int 时失败。
如果我写成 exec( 'select top '+ @count + '* from UBSNotice ' + 'ORDER BY PublishDate DESC '
); 提示By 附近有语法错误。
谢谢~
[解决办法]
set @strSQL= 'select top '+ cast(@count as varchar(100)) + '* from UBSNotice ' + 'ORDER BY PublishDate DESC '
[解决办法]
楼主拼的SQL语句缺空格:
1.* from 的*之前要有空格
2.ORDER BY 的order之前要有空格
CREATE PROCEDURE [dbo].[USP_UBSNotice_GetAllByCount]
@count int
AS
declare @strSQL varchar(6000) -- 主语句
set @strSQL= 'select top '+ RTRIM(@count) + ' * from UBSNotice ' + ' ORDER BY PublishDate DESC '
exec(@strSQL)