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.
| Author |
Topic |
|
paultervit
Starting Member
10 Posts |
Posted - 2008-07-09 : 09:13:36
|
| Hello AllSorry if this is a bit of a basic question for most of you but I'm having a bit of trouble with a query I'm writing. The query I have so far is as followsselect pl.PracticeCode , pl.practicename , u.username , a.testidfrom dbo.practicelookup plinner join dbo.[user] u on ( pl.PracticeCode = left(u.username, 5) )left outer join dbo.testaudit A on u.userid = a.useridwhere Month(a.eventtime) = 06 AND Year(a.eventtime) = 2008order by pl.PracticeCodeWhat I'm trying to do is get all values from praticelookup and user where the first join matches and then list these with all details in the testaudit table for June this year. The problem is when I add the where clause it filers out all practicelooup tables where no entry is available for testaudit. e.g. I'm gettingPC PN UN TI1 rt ty 12when I really wantPC PN UN TI1 rt ty 122 rt ty 0Hope this makes sense, but any help would really help me.ThanksPaul |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-09 : 09:16:30
|
[code]SELECT pl.PracticeCode , pl.practicename , u.username , a.testidFROM dbo.practicelookup pl INNER JOIN dbo.[user] u ON pl.PracticeCode = left(u.username, 5) left OUTER JOIN dbo.testaudit A ON u.userid = a.userid AND MONTH(a.eventtime) = 06 AND YEAR(a.eventtime) = 2008ORDER BY pl.PracticeCode[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
paultervit
Starting Member
10 Posts |
Posted - 2008-07-09 : 09:21:08
|
| thats the one thanks a lot khtan..... |
 |
|
|
|
|
|