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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case Statement Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 03/21/2014 :  05:27:08  Show Profile  Reply with Quote
Hey Guys

Hope your well

I need some urgent help

Aim – Create a case statement to say if “Arepeatable” is null, then use “Cont Band” Column. If “Arepeatable” is not null then use “ARepeatable”

My query is


--- Results ---
SELECT
[Lead ID]
,[MID Internal (Merchant ID)]
,[MID External (Merchant ID)]
---Calculating Contribution Banding --
Case
when [Business Turnover] between '0' and '6999' then '60'
when [Business Turnover] between '7000' and '14999' then '133'
when [Business Turnover] between '15000' and '19999' then '193'
when [Business Turnover] between '20000' and '29999' then '250'
when [Business Turnover] between '30000' and '49999' then '260'
when [Business Turnover] between '50000' and '99999' then '413'
when [Business Turnover] between '100000' and '199999' then '675'
when [Business Turnover] between '200000' and '299999' then '1000'
when [Business Turnover] between '300000' and '499999' then '1400'
when [Business Turnover] between '500000' and '999999' then '1875'
when [Business Turnover] between '1000000' and '4999999' then '5000'
when [Business Turnover] between '5000000'and '19999999' then '18750'
when [Business Turnover] between '20000000' and '49999999' then '42000'
when [Business Turnover] > '50000000' then '75000' else 'No Sales' end as [Cont Band] ,
[ARepeatable]

FROM [FDMS_PartnerReporting].[Staging].[Salesforce_MarketingReporting] SMR

left join [FDMS_PartnerReporting].[Staging].[Salesforce_MarketingReporting_Financials] SMF on SMR.[MID Internal (Merchant ID)] = SMF.[AccountId]

khtan
In (Som, Ni, Yak)

Singapore
17635 Posts

Posted - 03/21/2014 :  05:45:24  Show Profile  Reply with Quote
use a CTE


; with cte as
(
   < your existing query>
)
select  case when Arepeatable is null then [Cont Band] else [ARepeatable] end
from    cte



KH
Time is always against us

Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 03/21/2014 :  06:07:10  Show Profile  Reply with Quote
HI KH

So you the query is


SELECT
[Lead ID]
,[MID Internal (Merchant ID)]
,[MID External (Merchant ID)]
---Calculating Contribution Banding --

; with cte as
(
Case
WHEN [ARepeatable] is null then 'PPC'
when [Business Turnover] between '0' and '6999' then '60'
when [Business Turnover] between '7000' and '14999' then '133'
when [Business Turnover] between '15000' and '19999' then '193'
when [Business Turnover] between '20000' and '29999' then '250'
when [Business Turnover] between '30000' and '49999' then '260'
when [Business Turnover] between '50000' and '99999' then '413'
when [Business Turnover] between '100000' and '199999' then '675'
when [Business Turnover] between '200000' and '299999' then '1000'
when [Business Turnover] between '300000' and '499999' then '1400'
when [Business Turnover] between '500000' and '999999' then '1875'
when [Business Turnover] between '1000000' and '4999999' then '5000'
when [Business Turnover] between '5000000'and '19999999' then '18750'
when [Business Turnover] between '20000000' and '49999999' then '42000'
when [Business Turnover] > '50000000' then '75000' else 'No Sales' end as [Cont Band]
)
select case when Arepeatable is null then [Cont Band] else [ARepeatable] end
from cte
FROM [FDMS_PartnerReporting].[Staging].[Salesforce_MarketingReporting] SMR

left join [FDMS_PartnerReporting].[Staging].[Salesforce_MarketingReporting_Financials] SMF on SMR.[MID Internal (Merchant ID)] = SMF.[AccountId]
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.05 seconds. Powered By: Snitz Forums 2000