如何在不使用Dynamic SqlQuery的情况下实现这一目标?
我有这个查询,
SELECT TOP n FROM mytable WHERE ID = @id
获取n的值,
SELECT nCOUNT FROM myAnotherTable WHERE ID = @id
我可以使用Row_index()吗?
答案 0 :(得分:5)
尝试这样....但请确保您的select ncount
返回单行.....如果不是,则会选择顶行ncount
SELECT TOP(SELECT TOP 1 nCOUNT FROM myAnotherTable WHERE ID = @id) * FROM mytable WHERE ID = @id
SqlFiddle:http://www.sqlfiddle.com/#!3/75c76/1