Someone please explain the meaning of '1=2' in the below SQL query.
SELECT E.EmpID,
E.EmpName,
Country = CASE
WHEN T.Active = 'N'
AND 1 = 2 THEN 'Not Working Anymore'
ELSE C.Country_Name
END,
T.Contract_No
FROM Employees E (nolock)
INNER JOIN Contract T
ON T.Contract_No = E.Contract_No
LEFT JOIN Country C (nolock)
ON E.Country_ID = C.Country_ID
thanks
EDIT:- Corrected the slight mistake existed in the example SQL query given by me. @ ALL :- The query mentioned here is an example version of a big working query on which I have to reoslve something. I have created a sample scenario of SQL query for the sake of simplicity of question.
The reason you put the WHERE 1=2 clause in that SELECT INTO query is to create a field-copy of the existing table with no data. Table2 would be an exact duplicate of Table1 , including the data rows.
When 1/2 is calculated arithmetically, SQL Server does internally knows that the answer is 0.5. Later on when it has to display the answer, it will covert 0.5 to integer and result is displayed as a 0 (zero).
Consider above queries: Group by 1 means to group by the first column and group by 1,2 means to group by the first and second column and group by 1,2,3 means to group by first second and third column.
The SQL LIKE Operator The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters.
There is a good use for this 1=2
part of the WHERE
clause if you are creating a table from another, but you don't want to copy any rows. For example:
CREATE TABLE ABC_TEMP AS
SELECT * FROM ABC WHERE 1=2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With