﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / T-SQL (SS2K5)  / Where condition not equal to multiple columns - PUZZLE - who can solve this? / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 12:39:42 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>Phil,Thanks for the help. I had tried the or logic, but something else must have affected the results.</description><pubDate>Tue, 22 Jan 2013 10:00:44 GMT</pubDate><dc:creator>Mach1000</dc:creator></item><item><title>RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>[quote][b]Evil Kraig F (1/17/2013)[/b][hr]*facepalm* sorry about the earlier code.  Try this again:Alternatively:[code="sql"]SELECT	*,	CASE WHEN column2 &amp;lt;&amp;gt; 'AP' THEN 1 ELSE 0 END AS APtest,	CASE WHEN column3 &amp;lt;&amp;gt; 'U' THEN 1 ELSE 0 END AS Utest,	CASE WHEN column2 &amp;lt;&amp;gt; 'AP' AND column3 &amp;lt;&amp;gt; 'U' THEN 1 ELSE 0 END AS APUtestFROM	@Table1WHERE	NOT ( column2 = 'AP' AND column3 = 'U')[/code][/quote][quote][b]Phil Parkin (1/17/2013)[/b][hr][code="sql"]--Statement 2select * from @Table1where (column2 != 'AP' or column3 != 'U')[/code][/quote]For those not versed in boolean logic:NOT ( column2 = 'AP' AND column3 = 'U') --&amp;gt;NOT(column2 = 'AP') OR NOT(column3 = 'U') --&amp;gt;column2 != 'AP' or column3 != 'U'Which means: NOT ( column2 = 'AP' AND column3 = 'U') is equivalent to: column2 != 'AP' or column3 != 'U'.</description><pubDate>Thu, 17 Jan 2013 16:58:44 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>*facepalm* sorry about the earlier code.  Try this again:Alternatively:[code="sql"]SELECT	*,	CASE WHEN column2 &amp;lt;&amp;gt; 'AP' THEN 1 ELSE 0 END AS APtest,	CASE WHEN column3 &amp;lt;&amp;gt; 'U' THEN 1 ELSE 0 END AS Utest,	CASE WHEN column2 &amp;lt;&amp;gt; 'AP' AND column3 &amp;lt;&amp;gt; 'U' THEN 1 ELSE 0 END AS APUtestFROM	@Table1WHERE	NOT ( column2 = 'AP' AND column3 = 'U')[/code]</description><pubDate>Thu, 17 Jan 2013 16:14:52 GMT</pubDate><dc:creator>Evil Kraig F</dc:creator></item><item><title>RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>EDIT: Scratch this, bad code.  Sorry about that.</description><pubDate>Thu, 17 Jan 2013 16:10:17 GMT</pubDate><dc:creator>Evil Kraig F</dc:creator></item><item><title>RE: Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>[code="sql"]--Statement 2select * from @Table1where (column2 != 'AP' or column3 != 'U')[/code]</description><pubDate>Thu, 17 Jan 2013 15:30:25 GMT</pubDate><dc:creator>Phil Parkin</dc:creator></item><item><title>Where condition not equal to multiple columns - PUZZLE - who can solve this?</title><link>http://www.sqlservercentral.com/Forums/Topic1408641-338-1.aspx</link><description>Concerning the puzzle below, need a SQL guru to tell me how they solved this problem.Goal:To get statement 2 to produce the same results as statement 1 without having to string together the columns.DECLARE @Table1 TABLE(Column1 int IDENTITY(1,1),Column2 varchar(12),Column3 varchar(12))INSERT INTO @Table1 (Column2, Column3) VALUES ('UK','U')INSERT INTO @Table1 (Column2, Column3) VALUES ('AP','U')INSERT INTO @Table1 (Column2, Column3) VALUES ('AP','O')INSERT INTO @Table1 (Column2, Column3) VALUES ('UK','O')--Statement 1select * from @Table1where (column2 + column3 != 'APU')--Statement 2select * from @Table1where (column2 != 'AP' and column3 != 'U')</description><pubDate>Thu, 17 Jan 2013 15:25:24 GMT</pubDate><dc:creator>Mach1000</dc:creator></item></channel></rss>