Friday, February 24, 2012

AND - OR Sql syntax problem

Need a OR clause in the below statement but can't get it right.

Existing:

WHERE(L_PicTable.PicCity = @.PicCity)AND(L_PicTable.PicState = @.PicState)AND(L_PicTable.LinkType ='C')AND(L_PicTable.PicEnabled = 1)

NEED it to be:

WHERE(L_PicTable.PicCity = @.PicCity)AND(L_PicTable.PicState = @.PicState)AND(L_PicTable.LinkType ='C' ORL_PicTable.LinkType ='CS')AND(L_PicTable.PicEnabled = 1)

Can't get this clause to work - are my ('s wrong?

AND(L_PicTable.LinkType ='C' ORL_PicTable.LinkType ='CS')

Try with this:

L_PicTable.LinkType =N'C' OR L_PicTable.LinkType =N'CS'

|||

zoltac007:

AND(L_PicTable.LinkType ='C' ORL_PicTable.LinkType ='CS')

You can useANDL_PicTable.LinkType in ( 'C' ,'CS' ). One more thing, you don't need to place each and every AND clause in a separate pair of braces, they are used just when you want the output ( true or false ) to be returned back considering a set of the conditions as a whole.

|||

Hello zoltac,

There's no problem with the ()'s.

Your clause rewritten in boolean logic is:

(L_PicTable.PicCity = @.PicCity)AND(L_PicTable.PicState = @.PicState)AND (L_PicTable.LinkType ='C') AND(L_PicTable.PicEnabled = 1)

OR

(L_PicTable.PicCity = @.PicCity)AND(L_PicTable.PicState = @.PicState)AND (L_PicTable.LinkType ='CS') AND(L_PicTable.PicEnabled = 1)

What is the statement supposed to do?

Jeroen Molenaar.

|||

I am trying to select all records where Enabled is true, City, State match the page parameters AND the LinkType is either C or CS. There are only three values for the LinkType field, C, S or CS.

No comments:

Post a Comment