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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Getting results using three tables

Author  Topic 

karrojo
Starting Member

26 Posts

Posted - 2011-05-11 : 00:22:07

Good Day!

i really need all your help

i have a query, getting results using three tables.
1. MasterTable
2. ChecksTable
3. SuppChecksTable

however, i have the ff conditions
1. That in ChecksTable, i only get the checks issued on 2009 and compute the sum of amount
2. In SuppChecksTable, only checks issued in 2009.

i got the result that i expected, however if a record in SuppChecksTable has check issued in 2009 and other year, it gives 2 results:
(1) the checks issued in 2009 and
(2) the checks issued in previous years

i want to eliminate the result the checks are issued the previous years

here is my query:

select distinct a.col1, a.col2, a.col3, sum(b.Amt),
'SuppPay' = case
when (printed between '01/01/2009' and '01/01/2010') then c.col4
else '--'
end,
'Amount' = case
when (printed between '01/01/2009' and '01/01/2010') then c.col5
else '--'
end,
'Date_Printed' = case
when (printed between '01/01/2009' and '01/01/2010') then c.col6
else '--'
end
from MasterTable as a inner join ChecksTable as b
on a.col1 = b.col1
inner join SuppChecksTable as c
on a.col1 = c.col1
where (b.date between '01/01/2009' and '01/01/2010')
group by a.col1, a.col2, a.col3


your comments and suggestions will greatly help. thanks so much







khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-05-11 : 00:30:58
Why start a new thread ?

duplicate thread of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=160469




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -