返回多個值,我得到這樣的警告錯誤子查詢中SQLSERVER 2008
消息512,級別16,狀態1,行2子查詢返回多個1個 值。當子查詢遵循=,!=,<,< =, >,> =或當子查詢用作表達式時,這是不允許的。
,這我查詢
CREATE VIEW [dbo].[vwTrnLatihPerson2]
AS
SELECT
A.MKPersonID,
A.RegNo,
A.NoFix,
A.Nama,
NIK=
case
When A.RegNo<>0 And A.NoFix=0 then (Select NIK from vwMstKaryawan Where RegNo=A.Regno)
when A.NoFix<>0 And A.RegNo=0 then (Select NIK from vwMstBorongan Where FixNo=A.NoFix)
End,
Pendidikan=
case
When A.RegNo<>0 And A.NoFix=0 then (Select Pendidikan from vwMstKaryawan Where RegNo=A.Regno)
when A.NoFix<>0 And A.RegNo=0 then (Select Pendidikan from vwMstBorongan Where FixNo=A.NoFix)
End,
A.JabatanID,J.Jabatan,J.SubDeptID,D.SubDeptAbbr,D.SubDeptName,D.DivisiID,
Divisi=(Select Divisi From tblMstDivisi Where DivisiID=D.DivisiID),
NamaDivisi=(Select NamaDivisi From tblMstDivisi Where DivisiID=D.DivisiID),
StatusTK=
case
When A.RegNo<>0 And A.NoFix=0 then 'Karyawan'
when A.NoFix<>0 And A.RegNo=0 then (Select Pekerjaan from vwMstBorongan Where FixNo=A.NoFix)
End,
A.TglMasuk,
TglKeluar=
case
When A.RegNo<>0 And A.NoFix=0 then (Select TglKeluar from vwMstKaryawan Where RegNo=A.Regno)
when A.NoFix<>0 And A.RegNo=0 then (Select TglKeluar from vwMstBorongan Where FixNo=A.NoFix)
End,
A.NotActive
FROM
dbo.tblTrnLatihPerson A Left Outer Join
dbo.tblMstJabatan J On J.JabatanID=A.JabatanID LEFT Outer Join
dbo.tblMstSubDepartment D On D.SubDeptID=J.SubDeptID
--WHERE A.NotActive <> 1
GO
的消息說,子查詢中的一個返回更多的CTE比1排。您需要重新查看查詢和數據,以檢查是否有任何其他條件在子查詢中被遺漏。快速確定哪個子查詢將「TOP 1」添加到select語句,然後重新執行查詢 – Squirrel