存储过程中 带输出参数的问题。
时间:2011-11-16
来源:互联网
SQL code
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER proc [dbo].[proc_new] @id int=0, @num int=100, @returnid int output as select top (@num) * from employee where id>@id select @returnid = max([ID]) from (select top (@num) id from employee where id>@id ) as tmpTable declare @id int exec proc_new 2, 3, @id output print @id --这个打印的是数据库 employee表中最大的ID 而不是我想要的top (@num)中最大的ID。。 ================================================================================================= select @returnid = max([ID]) from (select top (@num) id from employee where id>@id ) as tmpTable这条有问题吗? 为什么我执行的时候他就给我打印数据库里边最大的ID 而不是在top(@num)里面找到最大的呢?
作者: a346729576 发布时间: 2011-11-16
select top (@num) * from employee where id>@id
在后面加上个order by 试试.例如:
select top (@num) * from employee where id>@id order by id
在后面加上个order by 试试.例如:
select top (@num) * from employee where id>@id order by id
作者: dawugui 发布时间: 2011-11-16
SQL code
select max(id) from (select top 10 ID from employee where id>100) as t --这样的话也是输出表中最大的ID 而不是我查询10条中最大的ID
作者: a346729576 发布时间: 2011-11-16
引用 1 楼 dawugui 的回复:
select top (@num) * from employee where id>@id
在后面加上个order by 试试.例如:
select top (@num) * from employee where id>@id order by id
select top (@num) * from employee where id>@id
在后面加上个order by 试试.例如:
select top (@num) * from employee where id>@id order by id
成功.。谢谢 可是为什么呢....
作者: a346729576 发布时间: 2011-11-16
引用 2 楼 a346729576 的回复:
SQL code
select max(id) from (select top 10 ID from employee where id>100) as t
--这样的话也是输出表中最大的ID 而不是我查询10条中最大的ID
SQL code
select max(id) from (select top 10 ID from employee where id>100) as t
--这样的话也是输出表中最大的ID 而不是我查询10条中最大的ID
SQL code
CREATE proc [dbo].[proc_new] @id int=0, @num int=100, @returnid int output as select top (@num) * from employee where id>@id select top (@num) @returnid = id from employee where id>@id go --这是别人给的另一种方法.. select top (@num) @returnid = id from employee where id>@id这句什么意思啊 。。看不懂.. 加了top不是取得很多条数据吗?为什么结果就返回了一条呢
作者: a346729576 发布时间: 2011-11-16
select top (@num) @returnid = id from employee where id>@id这句什么意思啊 。。看不懂..
加了top不是取得很多条数据吗?为什么结果就返回了一条呢
赋值语句只取一个值,多个值无效.而且这种写法不推荐.
加了top不是取得很多条数据吗?为什么结果就返回了一条呢
赋值语句只取一个值,多个值无效.而且这种写法不推荐.
作者: dawugui 发布时间: 2011-11-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28