SQL:如何像在SELECT TOP @amount中那样对TOP使用参数? [英] SQL: How do I use parameter for TOP like in SELECT TOP @amount?
本文介绍了SQL:如何像在SELECT TOP @amount中那样对TOP使用参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用vs2008查询构建器,我试图进行查询以获取"TOP
"命令的参数,然后遇到错误顶部表达式错误"
Using the vs2008 query builder, I’m trying to make a query that gets a parameter for the "TOP
" Command, and then I face an error "Error in top expression"
作品:
SELECT TOP 5 * FROM dbo.SomeTable
WHERE SomeColumn = SomeValue
不起作用:
SELECT TOP @param1 * FROM dbo.SomeTable
WHERE SomeColumn = SomeValue
替代文本http://www.freeimagehosting.net/uploads/f9b9354577.jpg
推荐答案
需要括号,并且仅适用于SQL Server 2005及更高版本
Need parenthesis, and only for SQL Server 2005 and above
SELECT TOP (@param1) ...
这篇关于SQL:如何像在SELECT TOP @amount中那样对TOP使用参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文