SQL Server 2008中的SQL查询错误 [英] Error in sql query in sql server 2008

查看:98
本文介绍了SQL Server 2008中的SQL查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我收到此错误:

Hi everyone,
I am getting this error:

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

请帮助,我已经尝试过自己解决问题,但仍然找不到正确的答案..
这是查询:

please help, I have tried to solve it on my own but still can''t find the right answer..
this is the query:

update tbl_M_MasterLogs set rptprobtype =
(Select [Problem Type]
from tbl_rpt_MasterData
where tbl_M_MasterLogs.CaseNo = tbl_rpt_MasterData.CaseNo)

非常感谢!

推荐答案

在子查询中添加TOP 1是我的快速答案.

Add TOP 1 to sub query is my quick answer.

update tbl_M_MasterLogs set rptprobtype =
(Select TOP 1 [Problem Type]
from tbl_rpt_MasterData
where tbl_M_MasterLogs.CaseNo = tbl_rpt_MasterData.CaseNo)



另一种方式是



The other way would be

update tbl_M_MasterLogs 
set rptprobtype = tbl_rpt_MasterData.[Problem Type] 
FROM tbl_M_MasterLogs 
INNER JOIN tbl_rpt_MasterData
ON tbl_M_MasterLogs.CaseNo = tbl_rpt_MasterData.CaseNo)


天哪!非常感谢!!!!!
Oh my holy GOD! thank you so much!!!!!


顺便问一下,为什么我会说"TOP 1"?
再次感谢天才! :-D
by the way can you explain to me why "TOP 1"?
Thank you again genius! :-D


这篇关于SQL Server 2008中的SQL查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆