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 2005 Forums
 Transact-SQL (2005)
 WHERE help

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2010-08-20 : 09:52:26
Hi,

I have this WHERE

WHERE
(CapID NOT IN
(SELECT CapID FROM dbo.tblLOAdhoc)) AND (Source <> 'SPC') AND (AdditionalFreeText NOT LIKE '%metallic%')

I want both the last two to be true, not one or the other. But when I add extra brackets like below it removes them and runs the query although they are seperate

WHERE
(CapID NOT IN
(SELECT CapID FROM dbo.tblLOAdhoc)) AND ((Source <> 'SPC') AND (AdditionalFreeText NOT LIKE '%metallic%'))

Thanks

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2010-08-20 : 09:54:24
To be clear, i'd like to include results where for example Source = 'SPC' and additionalfreetext ='solid'

Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-20 : 10:11:26
WHERE
(CapID NOT IN
(SELECT CapID FROM dbo.tblLOAdhoc)) AND (Source = 'SPC' and additionalfreetext ='solid'
)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2010-08-20 : 10:17:26
Hi,

That wouldn't work, I want to show everything except records where

(Source = special AND additionalfreetext contains 'metallic')

Thanks
Go to Top of Page

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2010-08-20 : 10:18:10
Sorry, by special I meant source='spc'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-20 : 12:18:03
WHERE
(CapID NOT IN
(SELECT CapID FROM dbo.tblLOAdhoc)) AND NOT (Source = 'SPC' and additionalfreetext ='solid')


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -