SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Constraint Violating Yak Guru

447 Posts

Posted - 12/10/2012 :  05:13:28  Show Profile  Reply with Quote
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

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

Flowing Fount of Yak Knowledge

2240 Posts

Posted - 12/10/2012 :  05:27:03  Show Profile  Reply with Quote
CASE WHEN [Omnipay_Account] IS NOT NULL THEN 1 ELSE 0 END [New Column]

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

Go to Top of Page

Very Important crosS Applying yaK Herder

52325 Posts

Posted - 12/14/2012 :  02:12:21  Show Profile  Reply with Quote
SIGN(COALESCE(Omnipay_Account,0)) AS newColumn

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000