我希望你們中的一些人能幫助我。我的SQL技能相當薄弱,而且我的工作中還有一個重要的SSIS工作現在無法運行。自從我開始沒有問題以來,它運行良好3年以上,但在過去的48小時內它失敗了兩次。錯誤如下:SQL子查詢返回多個值,困惑於查詢設計?
子查詢返回的值超過1。當 子查詢遵循=,!=,<,< =,>,> =或當子查詢用作 表達式時,這是不允許的。
我已經確認(盡我所能)沒有對數據庫結構/設計或任何內容進行更改,但遺憾的是,這就是我所能做的。否則這個可愛的問題屬於我。
我知道錯誤意味着我得到多個記錄時,我應該得到一個,但這是關於盡我所知。
該作業的流程如下:ProvUserDefinedDataRotated表每晚都被丟棄,然後在下面的查詢立即執行。
SELECT objectinternalid,
FaxComments = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 75
AND objectinternalid = Q.objectinternalid),
''),
FaxCommentsDate = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 76
AND objectinternalid =
Q.objectinternalid), ''
),
Specialty = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 77
AND objectinternalid = Q.objectinternalid),
''),
DepartmentFullDescript = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 78
AND objectinternalid =
Q.objectinternalid), ''),
Alerts1 = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 79
AND objectinternalid = Q.objectinternalid), '')
,
ProviderStatus = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 80
AND objectinternalid =
Q.objectinternalid), ''),
ProviderRole = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 81
AND objectinternalid =
Q.objectinternalid), ''),
ProfessionalTitle = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 82
AND objectinternalid =
Q.objectinternalid),
''),
SignatureBlockTitle = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 96
AND objectinternalid =
Q.objectinternalid), ''),
AlertsUsedWithProfTitles = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid =
98
AND objectinternalid =
Q.objectinternalid), ''),
ProfTitleAlertDescrpt = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 99
AND objectinternalid =
Q.objectinternalid), ''),
ProviderFullFaxNumber = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 102
AND objectinternalid =
Q.objectinternalid), ''),
NonEsig = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 112
AND objectinternalid = Q.objectinternalid), '')
,
EsigEWSTrainNotes = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 146
AND objectinternalid =
Q.objectinternalid),
''),
ESigEWSTrainedDate = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 147
AND objectinternalid =
Q.objectinternalid),
''),
EPICTrained = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 163
AND objectinternalid = Q.objectinternalid),
''),
EPICTrainedDate = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 164
AND objectinternalid =
Q.objectinternalid), ''
)
INTO provuserdefineddatarotated
FROM provuserdefineddata Q
GROUP BY objectinternalid
ORDER BY objectinternalid
從我有限的瞭解,好像這個查詢只是將數據複製到新創建的ProvUserDefinedDataRotated後表示,表被刪除表?
我在困惑什麼這樣
FaxComments = Isnull ((SELECT value
FROM provuserdefineddata
WHERE userdefinedfieldinternalid = 75
AND objectinternalid = Q.objectinternalid),
''),
個人陳述實際上意味着雖然。我完全不明白該代碼中發生了什麼。 :(
此查詢和/或指導如何解決設計任何解釋這在所有會如此感激。我一直在谷歌上搜索瘋狂不得要領。
謝謝!
請放心,無論誰寫這個SQL都做得不好,並留下了一個定時炸彈,最終會炸燬。 –