我試圖與工會都結合起來,查詢:對聯盟的不正確語法所有查詢
use SalesDWH
go
select cast(COUNT([specimen id]) as varchar) +'|'+[practice name]+'|'+b.[mlis practice id]+'|'+[practice code]+'|'+[Requesting Physician]+'|'+c.salesrep+'|'+
cast(c.dateestablished as varchar)+'|'+ c.practicecity+'|'+c.practicestate
from quicklabdump a
inner join qlmlismapping b
on (b.[quiklab practice code] = a.[practice code])
inner join PracticeandPhysician c
on (a.[Requesting Physician]=c.doctorfirstname+' '+c.DOCTORLASTNAME
and a.[practice code]=c.practicecode)
where DATEPART(yy, [DATE entered]) = 2011
and DATEPART(mm, [DATE entered]) = 12
group by a.[practice name],b.[mlis practice id],a.[practice code],
a.[Requesting Physician],c.salesrep,c.dateestablished, c.practicecity,c.practicestate
order by COUNT([specimen id]) desc
union all
select cast(COUNT([specimen id]) as varchar) +'|'+[practice name]+'|'+b.[mlis practice id]+'|'+[practice code]+'|'+[Requesting Physician]+'|'+c.salesrep+'|'+
cast(c.dateestablished as varchar)+'|'+ c.practicecity+'|'+c.practicestate
from quicklabdump a
inner join qlmlismapping b
on (b.[quiklab practice code] = a.[practice code])
inner join PracticeandPhysician c
on (a.[Requesting Physician]=c.doctorfirstname+' '+c.DOCTORLASTNAME
and a.[practice code]=c.practicecode)
where DATEPART(yy, [DATE entered]) = 2011
and DATEPART(mm, [DATE entered]) = 11
group by a.[practice name],b.[mlis practice id],a.[practice code],
a.[Requesting Physician],c.salesrep,c.dateestablished, c.practicecity,c.practicestate
order by COUNT([specimen id]) desc
但我收到此錯誤:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'union'.
我在做什麼錯?
非常感謝。如果我這樣做(11,12)...我想區分11中的數據和12中的數據,我該怎麼做?你能告訴我如何做一個CASE語句,並添加一個額外的輸出列,會說11或12? – 2011-12-29 21:38:42
它在組中。我將添加該列。 – Hogan 2011-12-29 21:39:38
這真是天才怪,非常感謝 – 2011-12-29 21:41:27