我有這個查詢,當我在Access中測試時,whoch運行良好,但我在外部C#程序中運行它
來自TSQL
(老實說,學習術語,所以我認爲TSQL對於我正在做的事情是正確的(不是))。當我嘗試將過程存儲在我的XSD文件的tableadapter中時,出現錯誤(請參閱下面的查詢)。因此,不會自動創建正確的XML模式。雖然查詢仍然運行它也給出了一個錯誤。我希望它能夠在沒有錯誤的情況下運行,但無法弄清楚錯誤究竟在哪裏。我試圖消除所有的「=」用CASE語句替換綜合投資框架,但後來我得到其他錯誤從查詢生成器查詢在Access中運行,但在C#數據集中生成錯誤
Error in list of function arguments: '=' not recognized.
Unable to parse query text.
(我可以張貼的嘗試是否會有所幫助)
SELECT IIF(ISNULL(Owners.OwnFirstName), Owners.OwnLastName,
Owners.OwnFirstName + ' ' + Owners.OwnLastName) AS [Owner's Name], SUM(iif(UnitBarcodes.NephStatus = 'N', 1, 0))
AS [Neph units], SUM(iif(UnitBarcodes.NephStatus = 'F', 1, 0)) AS [Filter units], COUNT(UnitBarcodes.NephStatus)
AS [Total Units]
FROM (Owners INNER JOIN
((UnitBarcodes INNER JOIN
AssembledUnits ON UnitBarcodes.ID = AssembledUnits.CaseID) INNER JOIN
OwnerUnits ON AssembledUnits.ID = OwnerUnits.AssembledUnitID) ON Owners.ID = OwnerUnits.OwnerID)
GROUP BY IIF(ISNULL(Owners.OwnFirstName), Owners.OwnLastName,
Owners.OwnFirstName + ' ' + Owners.OwnLastName)
錯誤信息
無論如何,感謝您的幫助!
編輯:
這是我以前在案件
SELECT (case when ISNULL(Owners.OwnFirstName) then Owners.OwnLastName else (Owners.OwnFirstName + ' ' + Owners.OwnLastName) end) AS [Owner's name],
SUM(case where UnitBarcodes.NephStatus = 'N' then 1 else 0 end))
AS [Neph units], SUM(case when UnitBarcodes.NephStatus = 'F' then 1 else 0 end)) AS [Filter units], COUNT(UnitBarcodes.NephStatus)
AS [Total units]
FROM (Owners inner JOIN
((UnitBarcodes inner JOIN
AssembledUnits ON UnitBarcodes.ID = AssembledUnits.CaseID) INNER JOIN
OwnerUnits ON AssembledUnits.ID = OwnerUnits.AssembledUnitID) ON Owners.ID = OwnerUnits.OwnerID)
GROUP BY (case when ISNULL(Owners.OwnFirstName) then Owners.OwnLastName else (Owners.OwnFirstName + ' ' + Owners.OwnLastName) end) AS [Owner's name]
而我得到的錯誤是
Error in list of function arguments: 'ISNULL' not recognized.
Error in list of function arguments: ')' not recognized.
Unable to parse query text.
EDIT2替換綜合投資框架的嘗試:
所以此查詢工作得很好
SELECT IIF(ISNULL(Owners.OwnFirstName), Owners.OwnLastName,
Owners.OwnFirstName + ' ' + Owners.OwnLastName) AS [Owner's Name], COUNT(UnitBarcodes.NephStatus)
AS [Total units]
FROM (Owners INNER JOIN
((UnitBarcodes INNER JOIN
AssembledUnits ON UnitBarcodes.ID = AssembledUnits.CaseID) INNER JOIN
OwnerUnits ON AssembledUnits.ID = OwnerUnits.AssembledUnitID) ON Owners.ID = OwnerUnits.OwnerID)
GROUP BY IIF(ISNULL(Owners.OwnFirstName), Owners.OwnLastName,
Owners.OwnFirstName + ' ' + Owners.OwnLastName)
但只要我添加任何款項(無論是通過案件或綜合投資框架)查詢產生一個錯誤。
爲什麼查詢設計者想改變'COALESCE(Owners.OwnFirstName + '', '')''到[COALESCE(Owners.OwnFirstName + '', '')'? – Brad 2011-12-19 15:21:06
@Brad不知道。 – 2011-12-19 15:23:22
當我嘗試運行你在那裏的東西時,我在查詢表達式SUM(CASE WHEN UnitBarcodes.NephStatus ='N'THEN 1 ELSE 0 END)'中得到'語法錯誤(缺少運算符)',然後突出顯示'WHEN'短語。 (這是當試圖在Access中,我也得到一個錯誤,只是di9fferent,在VS'IErrorInfo.Getdescription失敗,E_FAIL(0x80004005)。) – Brad 2011-12-19 15:27:42