SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



logical expression Expand / Collapse
Author
Message
Posted Thursday, May 26, 2005 3:20 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Hello,

I have a logical expression and want to make it on sql. negation(negation(A) union negation(B))
A means serviceId = 1 & B means serviceId = 6
negation(A) means serviceId<>1
negation(B) means serviceId<>6

but I don't know how to make negation for the whole expression

Thank you beforehand

Zineb

Post #185322
Posted Thursday, May 26, 2005 4:26 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
Am I misunderstanding something here? As I understand it, negation(A) union negation(B) would return everything. Since negation(A) returns everything except those where serviceId=1 (including those with serviceId=6), and negationB returns everything except those where serviceId=6 (including those with serviceId=1), the union between these should return everything. And the negation of that then would be nothing. So I would eveluate the expression to nothing. But I am probably missing something here.



--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #185334
Posted Thursday, May 26, 2005 4:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Hello Chris

Basically what I want is A interserction B which is A AND B. But in my case I can not do that because I can't write in the query "select propertyId where serviceId=6 AND serviceId=1". So I thought of an equivalent way to have A intersection with B, which is A AND B. I made 2 negations for A AND B and simplified the expression to negation ( negation(A) union negation(B)). I hope I'm clearer now. What do think?

Zineb

 

Post #185340
Posted Thursday, May 26, 2005 5:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
Is this what you want? Otherwise please post DDL and some sample data.

SELECT propertyId FROM tablename AS x
WHERE serviceId = 1
AND EXISTS (
SELECT * FROM tablename
WHERE serviceId = 6
AND propertyId = x.propertyId
)

On a side-note, SQL Server 2005 finally has the EXCEPT and INTERSECT relational operators.




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #185344
Posted Friday, May 27, 2005 4:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 17, 2005 12:20 PM
Points: 9, Visits: 1

Thank you very much Chris.

'EXISTS' worked for me yesterday but it's no more working today weird!

I used 'IN' instead and it's working fine now

Good luck

Zineb  

Post #185626
« Prev Topic | Next Topic »


Permissions Expand / Collapse