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
 General SQL Server Forums
 New to SQL Server Programming
 Query Question

Author  Topic 

wsilage
Yak Posting Veteran

82 Posts

Posted - 2014-09-25 : 12:10:57
Not sure if you can help me, but I have a query that I am trying to exclude a few things, but it is not working the way I want it too.

I am still seeing "TR" in my clm_att5 field and "*R-TG" in my clm_skut field


select clm_id1, clm_84b, clm_rcvd, clm_cc1, clm_cc2, clm_cc3, clm_clir, clm_65a, clm_tchg, clm_nego, clm_sppo, clm_form, clm_att1, clm_att2, clm_att3, clm_att4, clm_att5, clm_chast, clm_skut, clm_stades, clm_adjto, clm_adjfm
from impact.dbo.clm
where clm_rcvd > = '01/01/2014'
and clm_clir <> 3655 AND
clm_stades = 'HOLD' AND
((clm_att5 <> 'TR' and clm_skut <>'*R-TG') or
(clm_att1 <> 'NG' AND clm_skut <> '*R-NG'))


what am I doing wrong?

Thanks


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-09-25 : 12:21:57
If you with "*" mean a wildcard search, try this
SELECT	clm_id1,
clm_84b,
clm_rcvd,
clm_cc1,
clm_cc2,
clm_cc3,
clm_clir,
clm_65a,
clm_tchg,
clm_nego,
clm_sppo,
clm_form,
clm_att1,
clm_att2,
clm_att3,
clm_att4,
clm_att5,
clm_chast,
clm_skut,
clm_stades,
clm_adjto,
clm_adjfm
FROM impact.dbo.clm
WHERE clm_rcvd >= '01/01/2014'
AND clm_clir <> 3655
AND clm_stades = 'HOLD'
AND (
(clm_att5 <> 'TR' AND clm_skut NOT LIKE '%R-TG')
OR
(clm_att1 <> 'NG' AND clm_skut NOT LIKE '%R-NG')
)



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

wsilage
Yak Posting Veteran

82 Posts

Posted - 2014-09-25 : 12:33:10
Actually that isn't a wildcard. The "*" is part of our data *R-TG
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-09-25 : 12:39:02
Consider:

[code]
((clm_att5 <> 'TR' and clm_skut <>'*R-TG') or
(clm_att1 <> 'NG' AND clm_skut <> '*R-NG'))
[/ode]

Now imagine a row where clm_att5 = TR (so, not NG) and clm_skut = foobar
That would pass the second test and appear in your output
Go to Top of Page

wsilage
Yak Posting Veteran

82 Posts

Posted - 2014-09-25 : 13:40:54
Thanks!
Go to Top of Page
   

- Advertisement -