We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,240 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Exclude records in a query

Hmmm....
nope.

3
Contributors
3
Replies
5 Days
Discussion Span
1 Year Ago
Last Updated
4
Views
jovillanuev
Junior Poster in Training
80 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

If your item id list is fixed as shown above you can write where condition as given below

Select
v.ITEMID,
i.ITEMNAME,
AVG(CASE WHEN v.lvl=3 THEN v.LEADTIME END) AS ThreeMonths,
AVG(CASE WHEN v.lvl=6 THEN v.LEADTIME END) AS Sixmnths,
--activate to get the proportional leadtime
ROUND(SUM(CASE WHEN v.lvl=3 THEN v.Total END) / SUM(CASE WHEN v.lvl=3 THEN v.OrderQty END),0) AS ThreeProportionalLT,
ROUND(SUM(CASE WHEN v.lvl=6 THEN v.Total END) / SUM(CASE WHEN v.lvl=6 THEN v.OrderQty END),0) AS SixProportionalLT
From LeadTable v
left Outer Join Dynamics.dbo.INVENTTABLE i
On v.ITEMID = i.ITEMID
where i.ITEMID NOT IN ('HTC1012','HTC1016','HTC1017')
Group by v.ITEMID, i.ITEMNAME
order by v.ITEMID
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

If your item id list is fixed as shown above you can write where condition as given below

Select
v.ITEMID,
i.ITEMNAME,
AVG(CASE WHEN v.lvl=3 THEN v.LEADTIME END) AS ThreeMonths,
AVG(CASE WHEN v.lvl=6 THEN v.LEADTIME END) AS Sixmnths,
--activate to get the proportional leadtime
ROUND(SUM(CASE WHEN v.lvl=3 THEN v.Total END) / SUM(CASE WHEN v.lvl=3 THEN v.OrderQty END),0) AS ThreeProportionalLT,
ROUND(SUM(CASE WHEN v.lvl=6 THEN v.Total END) / SUM(CASE WHEN v.lvl=6 THEN v.OrderQty END),0) AS SixProportionalLT
From LeadTable v
left Outer Join Dynamics.dbo.INVENTTABLE i
On v.ITEMID = i.ITEMID
where i.ITEMID NOT IN ('HTC1012','HTC1016','HTC1017')
Group by v.ITEMID, i.ITEMNAME
order by v.ITEMID
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

I agree with urtrivedi... Indeed "NOT IN" looks like the clause you are looking for JOV... however if it is not fixed... find a query that only displays those items you want to exclude (1 column) and run the query as:

Code blocks are created by indenting at least 4 spaces
... and can span multiple lines
            Select
            v.ITEMID,
            i.ITEMNAME,
            AVG(CASE WHEN v.lvl=3 THEN v.LEADTIME END) AS ThreeMonths,
            AVG(CASE WHEN v.lvl=6 THEN v.LEADTIME END) AS Sixmnths,
            --activate to get the proportional leadtime
            ROUND(SUM(CASE WHEN v.lvl=3 THEN v.Total END) / SUM(CASE WHEN v.lvl=3 THEN v.OrderQty END),0) AS ThreeProportionalLT,
            ROUND(SUM(CASE WHEN v.lvl=6 THEN v.Total END) / SUM(CASE WHEN v.lvl=6 THEN v.OrderQty END),0) AS SixProportionalLT
            From LeadTable v
            left Outer Join Dynamics.dbo.INVENTTABLE i
            On v.ITEMID = i.ITEMID
            where i.ITEMID NOT IN (/*<INSERT SUB QUERY HERE>*/)
            Group by v.ITEMID, i.ITEMNAME
            order by v.ITEMID
Eagletalon
Junior Poster
135 posts since Mar 2011
Reputation Points: 44
Solved Threads: 16
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0656 seconds using 2.7MB