Groups | Blog | Home
all groups > sql server clients > october 2003 >

sql server clients : Find the right SQL query


andre simonse
10/2/2003 1:38:57 AM
I am looking for the right query for an SQL / Access database. Can
anyone help me? For example i give you the contents of a table and a
description of the statement.
Table1:
Column_A
1
2
3
4
5
6
The result of the query has to be 2 columns. The first column is
Column_A and the second column is an Alias column (e.g. Column_B).
In the query statement you give a condition that the values in Column_B
should be value "1" where the values from Column_A are greater than "4".
The other values in Column_B should be value "0".
The result should be:
Column_A | Column_B
1 | 0
2 | 0
3 | 0
4 | 0
5 | 1
6 | 1



*** Sent via Developersdex http://www.developersdex.com ***
Ray Higdon
10/2/2003 2:48:56 AM
select column_a, column_b=case when nbr < 4 then 0 else 1
end
from table

HTH

Ray Higdon MCSE, MCDBA, CCNA


[quoted text, click to view]
Allan Mitchell
10/2/2003 2:17:55 PM
SQL Server

SELECT
COLUMN_A,
CASE WHEN COLUMN_A < 5 THEN 0 ELSE 1 END AS COLUMN_B
FROM
TABLE

For Access you need to look at the IIF() function

--

----------------------------
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org



[quoted text, click to view]

AddThis Social Bookmark Button