Hi Jens
This answer does not return what I want
It only returns 1 record in total
I need the latest record for each customer
DDL
stat_date cust_code cycle p_end0 p_end1 p_end2 p_end3
30/11/05 COOSH M 0 0 0
0
25/12/05 COOSH W 100 0 0 0
18/12/05 AMAS W 10 0 32
0
25/12/05 AMAS W 20 0 0
32
I need to return COOSH for 25/12/05 but my original code returns both as
30/11/05 satisfies the monthly where
Any ideas please
Regards
Steve
[quoted text, click to view] "Jens" <Jens@sqlserver2005.de> wrote in message
news:1135237586.746913.84020@g43g2000cwa.googlegroups.com...
Hit Steve,
you sure have to put that back in your formatted sql string syntax, but
that be the solution you are searching for:
Select TOP 1 *
from [stheader]
inner join [customer] on
customer.[cust_code] = stheader.[cust_code]
where
([stheader].[stat_date] = maxfn and
[stheader].[cycle] = 'F')
OR
([stheader].[stat_date] = 'maxmonth' and
[stheader].[cycle] = 'M')
OR
([stheader].[stat_date] = 'maxweek'
and [stheader].[cycle] = 'W')
ORDER BY stat_date
Try to avoid the "*" in production code, something would have been even
clearer to me if you wouldn´t use the asteriks in there. I know for
some developers thats a religious war, but save yourself a lot time and
code your columnNames. BTW why didn´t you use a view for this, that
would be a good work for this query.
BTW: please provide us with DDL and sample data to help you better.
http://www.aspfaq.com/5006 HTH, jens Suessmeyer.