[已解决]选择顶部 [英] [Solved] Select Top
本文介绍了[已解决]选择顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个gridview,它显示有关用户及其手机号码的数据.它可以包含100条记录,并且我有一个带移动计数的文本框.通过移动数量,我将根据其大小显示网格.
示例:我有100条记录,我只想看到10条记录,那么我将在文本框中写10条记录,而网格将仅显示前10条记录.
我试图做到这一点:
create proc test (@mobilecount bigint) as begin select top @mobilecount from tbl_mobiles
有帮助吗?
谢谢
更新:
由OP自己解决.
解决方案
使用 Exec () [^ ]实现动态执行.
创建 proc 测试 ( @ mobilecount bigint ) 为 开始 声明 @ SQL varchar (最大值) SET @ SQL = ' 从tbl_mobiles的中选择顶部的' + @ mobilecount + ' EXEC ( @ SQL )
Hi All,
I have a gridview that displays data about users and their mobile numbers. It can have 100 records in it, and I have a text box that takes mobile count. By that mobile count, I will display the grid according to its size.
Example: I have 100 records and I want to see 10 only then I will write 10 in the text box and the grid will display top 10 only.
I tried to make that:
create proc test (@mobilecount bigint) as begin select top @mobilecount from tbl_mobiles
Any help?
Thanks
UPDATE:
Solved by OP herself.
解决方案
Use Exec()[^] to achieve dynamic execution.
create proc test (@mobilecount bigint) as begin Declare @SQL varchar(max) SET @SQL = 'select top '+@mobilecount+' from tbl_mobiles' EXEC(@SQL)
alter proc test ( @mobilecount bigint ) as begin declare @n int set @n=@mobilecount select top (@n) mobile,ownerName from tbl_mobiles end
这篇关于[已解决]选择顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文