Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > Find the right SQL query
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 23rd April 06:04
andre simonse
External User
 
Posts: 1
Default Find the right SQL query



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 ***
Don't just participate in USENET...get rewarded for it!
  Reply With Quote


  sponsored links


2 23rd April 06:04
ray higdon
External User
 
Posts: 1
Default Find the right SQL query



select column_a, column_b=case when nbr < 4 then 0 else 1
end
from table

HTH

Ray Higdon MCSE, MCDBA, CCNA


database. Can

table and a


column is

Column_B).

values in Column_B

greater than "4".

***
  Reply With Quote
3 23rd April 06:04
allan mitchell
External User
 
Posts: 1
Default Find the right SQL query


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
http://www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666