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)
 Query Required

Author  Topic 

hksharmaa
Starting Member

16 Posts

Posted - 2012-02-07 : 06:17:17
Hi All,

I want to write a query . I have a Table which have following fields.
Drum No,Drum Wt,AP,TP,SP,LP,RP,IP,KP.
I want those Drum No. whose Wt is 1200 and
AP is between 10-14
TP is between 1-2
SP is between 60-70
LP is between 20-25
RP is between 1-5
IP is between 4-6
KP is between 8-10

I needed a query for that. There are approx. 10,000 Drum No in the Table.

Output should stop at when the above all conditions are matched

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-02-07 : 06:51:50
You have almost written the query yourself:
SELECT DrumNo
FROM YourTable
WHERE
Wt = 1200
AND AP BETWEEN 10 AND 14
AND TP BETWEEN 1 AND 2
--... etc.
That will give you ALL the drums that match that criteria. If you want only just one, add a TOP clause as in
SELECT TOP (1) DrumNo
FROM YourTable
WHERE
Wt = 1200
AND AP BETWEEN 10 AND 14
AND TP BETWEEN 1 AND 2
--... etc.
To be sure that you get the drum with the lowest drum number, add an order by clause too.
SELECT TOP (1) DrumNo
FROM YourTable
WHERE
Wt = 1200
AND AP BETWEEN 10 AND 14
AND TP BETWEEN 1 AND 2
--... etc.
ORDER BY
DrumNo
Go to Top of Page
   

- Advertisement -