April 22, 2017 at 5:09 pm
Hi,
I want to select result filtered by more than a value by a row.
I don't know if it's possible or there's a way to make it work,
This is my example :
id | Answer | visible | type |
1 | answer1 | 0 | 14 |
2 | Mexico | 1 | 10 |
3 | 101202 | 0 | 2 |
4 | 1275, | 1 | 14 |
I want to select row where type <> 14 and visible = 0 at the same row,
it means my query will return this result :
id | Answer | visible | type |
1 | answer1 | 0 | 14 |
2 | Mexico | 1 | 10 |
3 | 101202 | 0 | 2 |
Thank you for the help
April 22, 2017 at 5:43 pm
benkraiemchedlia - Saturday, April 22, 2017 5:09 PMHi,I want to select result filtered by more than a value by a row.
I don't know if it's possible or there's a way to make it work,
This is my example :
id Answer visible type 1 answer1 0 14 2 Mexico 1 10 3 101202 0 2 4 1275, 1 14 I want to select row where type <> 14 and visible = 0 at the same row,
it means my query will return this result :
id Answer visible type 1 answer1 0 14 2 Mexico 1 10 3 101202 0 2 Thank you for the help
Wow, I have no idea what you logic is supposed to be with your description and sample data/output. Can you put text beside each output row describing the logic as to why it is included? Also state why row 4 did not make it into the output.
Also, did you know you can use parentheses, AND and OR in the WHERE clause? Seems to me you could combine those in some boolean-appropriate way to achieve your results.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 22, 2017 at 8:42 pm
benkraiemchedlia - Saturday, April 22, 2017 5:09 PMHi,I want to select result filtered by more than a value by a row.
I don't know if it's possible or there's a way to make it work,
This is my example :
id Answer visible type 1 answer1 0 14 2 Mexico 1 10 3 101202 0 2 4 1275, 1 14 I want to select row where type <> 14 and visible = 0 at the same row,
it means my query will return this result :
id Answer visible type 1 answer1 0 14 2 Mexico 1 10 3 101202 0 2 Thank you for the help
According to TYPE <> 14, the row where ID = 1 should be excluded.
According to VISIBLE = 0, the row where ID = 2 should be excluded.
According to TYPE <> 14 AND VISIBLE = 0, the row where ID = 3 should be returned.
According to TYPE <> 14 AND VISIBLE = 0, the row where ID = 4 should be returned.
Is that correct? If not, then I'm with Kevin and have no clue how your given output matches your stated criteria and you need to explain.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 23, 2017 at 7:15 am
Thom A - Sunday, April 23, 2017 6:36 AMThis almost sounds like the OP is wants to do an XOR statement, so the logic wanted is? Visible = 0 XOR [Type] <> 14
Seems to fit. The T-SQL implementation being something like this SELECT columns
FROM table
WHERE NOT (TYPE = 14 AND VISIBLE <> 0)
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
April 23, 2017 at 7:51 am
Phil Parkin - Sunday, April 23, 2017 7:15 AMThom A - Sunday, April 23, 2017 6:36 AMThis almost sounds like the OP is wants to do an XOR statement, so the logic wanted is? Visible = 0 XOR [Type] <> 14Seems to fit. The T-SQL implementation being something like this
SELECT columns
FROM table
WHERE NOT (TYPE = 14 AND VISIBLE <> 0)
AND ([Type] = 14 OR Visible <> 0);
Actually it would be this. (I've amended Phil's code).
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
April 23, 2017 at 8:44 am
Very cool analysis, guys.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 23, 2017 at 9:04 am
Thom A - Sunday, April 23, 2017 7:51 AMPhil Parkin - Sunday, April 23, 2017 7:15 AMThom A - Sunday, April 23, 2017 6:36 AMThis almost sounds like the OP is wants to do an XOR statement, so the logic wanted is? Visible = 0 XOR [Type] <> 14Seems to fit. The T-SQL implementation being something like this
SELECT columns
FROM table
WHERE NOT (TYPE = 14 AND VISIBLE <> 0)
AND ([Type] = 14 OR Visible <> 0);Actually it would be this. (I've amended Phil's code).
For once, I have to pull you up, Thom.
Here is a truth table for the assumed logic:
Thus, not (14 and not 0) captures all outcomes, without need for further embellishment.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
April 23, 2017 at 12:29 pm
This seems to be the simplest form of the OP's requirement.
SELECT columns
FROM table
WHERE TYPE <> 14
OR VISIBLE = 0;
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply