Microsoft
Software
Hardware
Network
Question : select records
Hi,
I have a table in my database which contains the lead time information from my suppliers for each item.
I have a situation where I would like to know the supplier with the lowest lead time for each item.
I have so far been able to generate a disctinct query (below), however in some cases multiple suppliers will have the same lead time and therefore my query returns multiple records.
Example
select distinct itemcode, min(deliverytimeindays) as Leadtime,crdnr,mainaccount
from itemaccounts where itemcode like 'CX%' group by itemcode,crdnr,mainaccount
Returns
itemcode Leadtime crdnr mainaccount
CX_RM1 14 1369 0
CX_RM1 14 2120 0
CX_RM1 14 5165 1
I would therefore like a single record to be returned on a logic when multiple records exist (as above), whereby if the supplier is the 'Mainaccount' then return this, otherwise the supplier with the lowest number (crdnr)
Any tips would be very helpful.
Thanks
R
Answer : select records
CX_RM1 14 1369 0
CX_RM1 14 2120 0
CX_RM1 14 5165 1
I'm not sure I understand what you want. Of the three records returned from your query, which one do you want returned and why?
Random Solutions
Excel Formula Error: Formula repeats itself and does not display answer
ssh shell not working on solaris 10
Can I reserve a drive letter for a USB external drive
Need to Defrag Information store (Exchange 2003)
called function not executing - why?
Separate SSIS server for ETL Tasks
wxqwa.sys file found in system32/drivers...is this malware?
Reformat of a Dell Poweredge 1900 with a single RAID5 array on PERC5/i - loss of data on 2nd partition?
Using ColdFusion Flash Forms to change group membership/moving data from one cfgrid to another.
PHP: Zap everything after &