2011-04-03 60 views
0

這是我試圖執行的查詢,但它說找不到存儲過程的所有表。查詢多個數據

alltable(選擇轉換(日期時間,轉換(CHAR(10),[日期/時間],101))[日期/時間],[通過],[接收量] FROM交易 UNION ALL

選擇轉換(日期時間,轉換(CHAR(10),[日期/時間],101))[日期/時間],[通過],[接收量] FROM DTH UNION ALL

選擇轉換(日期時間,轉換(char(10),[Date/Time],101))[Date/Time],[Through],[Received Received] FROM Utilities UNION ALL

選擇轉換(日期時間,轉換(CHAR(10),[日期/時間],101))[日期/時間],[通過],[接收量] 來自移動 UNION ALL

選擇轉換(datetime,convert(char(10),[Date/Time],101))[Date/Time],[Through],[Received Received] FROM ISP) SELECT convert(datetime,convert(char(10), [Date/Time],101))[Date/Time],[Through],SUM([Received Received]) FROM alltable GROUP BY convert(datetime,convert(char(10),[Date/Time] )),[通過]

+1

請發表您到目前爲止寫的代碼。人們通常不喜歡只爲你寫代碼。事實上,這是一個工作描述,而不是一個問題。 – 2011-04-03 04:37:43

回答

0

這可能不是有效的,但它會工作...第一...

選擇從每個表和聯合在一起想要的3場......作爲視圖...那麼你總和/組通過對視......

恩.... 創建視景 作爲 選擇的DateField,服務,從表1 工會 選擇的DateField,服務AmountRecieved,從表2 工會 選擇的DateField,服務AmountRecieved,從表3 AmountRecieved ...

選擇總和(amountREcieved)的DateField ,Servi CE 組通過的DateField,服務

GL

2

你可以嘗試這樣的事:

with AllTables as (
    select dateadd(day, 0, datediff(day, 0, [Date/Time])) as Date, Service, AmountReceived from Table1 union all 
    select dateadd(day, 0, datediff(day, 0, [Date/Time])) as Date, Service, AmountReceived from Table2 union all 
    select dateadd(day, 0, datediff(day, 0, [Date/Time])) as Date, Service, AmountReceived from Table3 union all 
    select dateadd(day, 0, datediff(day, 0, [Date/Time])) as Date, Service, AmountReceived from Table4 union all 
    select dateadd(day, 0, datediff(day, 0, [Date/Time])) as Date, Service, AmountReceived from Table5 
) 
select Date, Service, sum(AmountReceived) as AmountReceived 
from AllTables 
group by Date, Service 

只要確保你使用union all,而不是union

+0

該列的名稱是'[Date/Time]',而不是'DateTime',但基本上與我要發佈的內容類似。 – 2011-04-03 11:30:42

+0

謝謝,我糾正了它。 – sventevit 2011-04-03 12:40:19