|
-
Apr 10th, 2019, 03:01 AM
#1
Thread Starter
Member
[RESOLVED] SQL SELECT with multiple condition (SQL Server 2017)
Hi, I'm sorry to post it here, but I didn't find a place for SQL issues.
I'm trying to extract values from my SQL table for my vb.net app but I have some troubles...
I am trying to do that :
SQL Code:
SELECT * FROM "My_table"
WHERE (Condition1 = 1 AND Condition2 = 2) OR
((Condition1 = 2 AND Condition2 = 1) AND (Condition3 =1 OU Condition3 = 2 OU Condition3 = 3)
But when I try it, SQL change the place of my parentheses. 
Thank you for your help and sorry if I am in the wrong place...
Have a good day!
-
Apr 10th, 2019, 06:22 AM
#2
Re: SQL SELECT with multiple condition (SQL Server 2017)
You seem to be missing a close bracket.
-
Apr 10th, 2019, 06:40 AM
#3
Re: SQL SELECT with multiple condition (SQL Server 2017)
 Originally Posted by Macronaute
Hi, I'm sorry to post it here, but I didn't find a place for SQL issues.
That would be the Database Development section... I've notified the moderators...
-tg
-
Apr 10th, 2019, 06:42 AM
#4
Thread Starter
Member
Re: SQL SELECT with multiple condition (SQL Server 2017)
I'm sorry, I did it right on SQL Server, but when I copied it in the forum I missed it.
So to be clearer, I write that :
SQL Code:
WHERE (Soldee IS NULL AND Resp_MET = 'TEST' AND Emet <> 'init' AND CPRC = 'NON') OR
((Soldee IS NULL AND Resp_MET = 'TEST' AND Emet <> 'init' AND CPRC = 'OUI') AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = ''))
And it give me that :
SQL Code:
WHERE (Soldee IS NULL) AND (Resp_MET = 'TEST') AND (Emet <> 'init') AND (CPRC = 'NON') OR
(Soldee IS NULL) AND (Resp_MET = 'TEST') AND (Emet <> 'init') AND (CPRC = 'OUI') AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = '')
I did not understand why.
-
Apr 10th, 2019, 06:43 AM
#5
Thread Starter
Member
Re: SQL SELECT with multiple condition (SQL Server 2017)
Thank you, I looked where to post it this morning but I didn't find !
-
Apr 10th, 2019, 07:36 AM
#6
Re: SQL SELECT with multiple condition (SQL Server 2017)
What are you using to write your queries? SQL Server Management Studio (SSMS)? If so, then you must have a plugin or something because SSMS by itself doesn't change queries.
Code:
(Soldee IS NULL AND Resp_MET = 'TEST' AND Emet <> 'init' AND CPRC = 'NON') OR
((Soldee IS NULL AND Resp_MET = 'TEST' AND Emet <> 'init' AND CPRC = 'OUI') AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = ''))
(Soldee IS NULL) AND (Resp_MET = 'TEST') AND (Emet <> 'init') AND (CPRC = 'NON') OR
(Soldee IS NULL) AND (Resp_MET = 'TEST') AND (Emet <> 'init') AND (CPRC = 'OUI') AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = '')
It looks like what ever it is, is removing the outer parens from the or clause... but I think the whole thing can be simplified anyways...
Code:
( (Soldee IS NULL) AND (Resp_MET = 'TEST') AND (Emet <> 'init') ) AND
(
(CPRC = 'NON') OR
(
(CPRC = 'OUI') AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = '')
)
)
-tg
-
Apr 10th, 2019, 07:42 AM
#7
Re: SQL SELECT with multiple condition (SQL Server 2017)
Thread moved to the 'Database Development' forum
This bit:
Code:
AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = '')
...can be simplified to:
Code:
AND Decision_Q IN('OKAY', 'REFU', '')
-
Apr 10th, 2019, 07:45 AM
#8
Thread Starter
Member
Re: SQL SELECT with multiple condition (SQL Server 2017)
Thank you for your return, but I just resolve my issue and I am a bit ashamed because of my mistake.
To explain, I was writing in the SQL Server Management Studio (SSMS) but in the "Edit 200 rows" (You can show the SQL pane to wright queries).
Now, I taped it in the "Select 1000 rows" and it works perfectly !
Thank you and excuse me for my silly question
-
Apr 10th, 2019, 07:47 AM
#9
Thread Starter
Member
Re: SQL SELECT with multiple condition (SQL Server 2017)
 Originally Posted by si_the_geek
Thread moved to the 'Database Development' forum
This bit:
Code:
AND (Decision_Q = 'OKAY' OR Decision_Q = 'REFU' OR Decision_Q = '')
...can be simplified to:
Code:
AND Decision_Q IN('OKAY', 'REFU', '')
Thank you for it too!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|