查询不会每次都返回所有行
我们有两个简单的查询(在存储过程内,由网站使用):
if @a = 1
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'yyyy'
end
else
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'zzzz'
end
第一个查询从来没有问题(@a = 1)。第二个应该返回 48 行(表不经常写入)。每天一次或两次(数百次点击)第二个查询返回 10 或 30 行(为了调试,我将 @@rowcount 插入到另一个表中)。 ,为了强制它返回 48 行,我尝试了如下操作:
else
again:
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'zzzz'
if @@rowcount <> 48 goto again
end
因此 它会持续循环几分钟(从不返回 48 行),直到我杀死 spid。
任何想法都会有所帮助。 谢谢
We have two simple queries (inside stored procedure, used by website) as:
if @a = 1
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'yyyy'
end
else
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'zzzz'
end
There is never problem with first query (@a = 1). Second one is supposed to return 48 rows (tables are not written often). Ones or twice per day (out of hundreds hits) second query returns 10 or 30 rows (To debug i inserted @@rowcount into another table). So to force it to return me 48 rows I tried something like this:
else
again:
begin
select a.col1, a.col2 , b.col1 from table1 a join table2 b
on a.id = b.id
where a.col1 = 'zzzz'
if @@rowcount <> 48 goto again
end
,
it keeps looping for minutes (never returns 48 rows) until i kill the spid.
Any idea would help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您返回 10 或 30,则组合永远不会是 48。
将其更改为:
尽管如此,我相信您的解决办法没有多大意义。
你的第二个选择真的有 48 行吗?
if you are returning 10 or 30, the combination will never be 48.
change it to:
even though, I believe your work around doesnt make much sense.
Do you really have 48 rows on your second select?