| Author |
Topic |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-12-30 : 10:16:16
|
| Hello,Looking at the sql below, how can I separate the and clause and the OR clause ( ID = '1' OR ID = '2' OR ID = '3' OR ID = '4' OR ID = '5' OR ID = '14' AND f.Account = '4' ) Result:( ID = '1' OR ID = '2' OR ID = '3' OR ID = '4' OR ID = '5' OR ID = '14') AND (f.Account = '4' ) Thanks |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-30 : 10:31:42
|
just this would dowhere ID in ('1','2','3','4','5','14') and (f.Account = '4' ) |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-12-30 : 10:34:38
|
| I think you mis-understood.I am building the sql dynamically and so I would like to separate the AND and OR clauses.Any thoughts please?Thanks |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-30 : 10:37:32
|
quote: I am building the sql dynamically and so I would like to separate the AND and OR clauses.
Can you explain this a li'l better..you want to add the "AND" clause dynamically based on some other condition? |
 |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2009-12-30 : 10:39:27
|
| I think you may have to supply a bit of code showing how it is currently being built, if you are adjoining new 'OR's and 'AND's from a condition you would just need to add another condition to check if the left 2 characters are OR and if not close the paranthesis and begin the AND. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-12-30 : 10:40:51
|
| I am building the query based on several fields, operators, etc...the sql I placed above is what gets built. Now I want to make sure there is a bracket around the fields with OR and there is a bracket around the fields with AND. This way I will be able to separate the OR fields with the AND fields as indicated in the query I posted under the result section. Thanks |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-12-30 : 10:44:52
|
| I don't know if anyone can suggest a solution without knowing how you are building the query. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-12-30 : 10:47:06
|
| I think I can do this by adding extra columns for ( and )Thanks anyway. |
 |
|
|
DP978
Constraint Violating Yak Guru
269 Posts |
Posted - 2009-12-30 : 10:50:08
|
| again..you probably have a navarchar field being built like...@mySql = @mySql + @myConditionBefore doing that step do something like...If Left(ltrim(@mycondition), 3) = 'AND'@mysql = mySql + ')' +... --Need to replace AND with AND (Else@mysql = @mySql + @myCondition |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2009-12-30 : 11:01:06
|
| I have solved the problem by using two extra fields. one for ( and another for ) where appropriate.Thanks anyway. |
 |
|
|
|