我有一個查詢,我在SQL中開發並運行正常,但是當我將查詢放入SQL Server(或.Net)查詢生成器時,它會生成錯誤。這裏要說的是像我寫SQL Server查詢生成器錯誤?
此查詢的例子我寫什麼(工作)
Select Case when Table1.[Col 1] is null then Table2.[Col 1] Else Table1.[Col 1] END as 'col1' From
(Select Sum(Table3.[Col 1]) as 'col 1', Table3.[groupby col] from Table3 Group by Table3.[groupbycol]) as Table1 FULL OUTER JOIN (Select Sum(Table3.[Col 1]) as 'col 1', 'Total' as 'groupby col' from Table3) as Table2 ON Table1.[groupby col] = Table2.[groupby col]
但當時如果我在SQL或asp.net查詢生成器打開這個「改進「它使中斷查詢,現在看起來是這樣的
Select
Case
when Table1. 'Col 1' is null
then Table2. 'Col 1'
Else Table1. 'Col 1'
END as 'col1'
From
(Select
Sum(Table3.[Col 1]) as 'col 1',
Table3.[groupby col]
from
Table3
group by
Table3.[groupbycol]) as Table1
FULL OUTER JOIN
(Select
Sum(Table3.[Col 1]) as 'col 1',
'Total' as 'groupby col'
from Table3 as Table3_1) as Table2 ON Table1. 'groupby col' = Table2. 'groupby col'
不再適用,因爲它,因爲它取代了[]與和列名前添加一個空格和表3創建別名在第二個查詢中,然後不會將該別名分配給使用該表的其他時間
任何人都知道是什麼原因造成這似乎每次我打開一個查詢構建器它可能搞砸查詢
感謝
引用標識符 – Jodrell