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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case statement
 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

2242 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

52326 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  
 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.04 seconds. Powered By: Snitz Forums 2000