Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 why doesnt my query work

Author  Topic 

jaskalirai
Starting Member

31 Posts

Posted - 2007-12-06 : 10:25:38
select distinct
a.Patients,
b.Patients,
a.pct,
b.pct

from
(
select count(*) as Patients, [pct of res] as pct
from testing
where [18 week wait] <= 18
group by [pct of res]
) as a right outer join
(select distinct[pct of res] from testing) as c on a.pct=c.[pct of res] and a.pct <> 'null' --is not null

( select count(*) as Patients, [pct of res] as pct
from testing
where [18 week wait] >18
group by [pct of res]
) as a left outer join as b on c.[pct of res]=b.pct

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-06 : 10:27:51
The line after "<> 'null'" starts with an paranthesis.
It should be some kind of JOIN, right?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2007-12-06 : 10:29:18
did you finish writing your question fully?

are we just talking about all the synatx errors? or are you trying to do something specific and are struglling with the logic?

Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-06 : 10:29:31
Please post your actual query.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-06 : 10:29:57
[code]
select distinct
a.Patients,
b.Patients,
a.pct,
b.pct

from
(select count(*) as Patients, [pct of res] as pct
from testing
where [18 week wait] <= 18
group by [pct of res]
) as a right outer join
(select distinct[pct of res] from testing) as c
on a.pct=c.[pct of res] and a.pct <> 'null' --is not null
--Join missing here
( select count(*) as Patients, [pct of res] as pct
from testing
where [18 week wait] >18
group by [pct of res]
) as a left outer join /*This jopin shouldn't be here*/ as b on c.[pct of res]=b.pct
[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-06 : 10:32:12
Rick, then there are two derived tables A (with same content) !
I think OP pasted query incorrectly.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-06 : 11:32:38
Yeah, I kind of guessed that the second select should actually be b.
Go to Top of Page
   

- Advertisement -