首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL存储过程传递参数的有关问题

2012-01-21 
SQL存储过程传递参数的问题SQL codeSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [dbo].[pro

SQL存储过程传递参数的问题

SQL code
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [dbo].[proc_new]@id int=0,@mun int=100asselect top @num * from employee where id>@idGOSET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER OFFGO-----------------------------------error:消息 102,级别 15,状态 1,过程 proc_newproc,第 5 行'@num' 附近有语法错误。


[解决办法]
SQL code
--加个括号试试哟select top (@num) * from employee where id>@id
[解决办法]
SQL code
ALTER proc [dbo].[proc_new]@id int=0,@num int=100  --变量名定义错了asselect top (@num) * from employee where id>@id --加括号GO
[解决办法]
2005中top支持参数
select top (@num) * from employee where id>@id

2000的话需要拼接成动态sql以后执行

exec ('sekect top '+cast(@num as varchar(10))+' * from employee where id>'+cast(@id as varchar(10)))

[解决办法]
SQL code
2005的话select top (@num) * from employee where id>@id2000的话exec ('sekect top '+ltrim(@num)+' * from employee where id>'+ltrim(@id)' 

热点排行