Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case statement

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2012-12-10 : 05:13:28
Hey Guys

This is really basic question, but i am really struggling

I believe i need a case when statement but not sure how to go around it.

In the [Omnipay_Account]column there is only ever two outcomes

Either Null
Or a number

For eg

FDMSAccountNo Omnipay_Account
878000000884 NULL
878000001882 NULL
878000002880 NULL
878000003888 NULL
878000000884 000001
878000001882 000012
878000002880 000013
878000003888 000014


I want to create a separate coloumn to say, if the [Omnipay_Account] is null then produce a 0, if it has a number to produce 1.


FDMSAccountNo Omnipay_Account New column
878000000884 NULL 0
878000001882 NULL 0
878000002880 NULL 0
878000003888 NULL 0
878000000884 000001 1
878000001882 000012 1
878000002880 000013 1
878000003888 000014 1

This is my query so far

SELECT
[FDMSAccountNo],
[Omnipay_Account]
FROM [FDMS].[dbo].[Dim_Outlet]


bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2012-12-10 : 05:27:03
SELECT
[FDMSAccountNo],
[Omnipay_Account],
CASE WHEN [Omnipay_Account] IS NOT NULL THEN 1 ELSE 0 END [New Column]

FROM [FDMS].[dbo].[Dim_Outlet]

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-14 : 02:12:21
SIGN(COALESCE(Omnipay_Account,0)) AS newColumn

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -