By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,377 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

SQL Addition Problem

P: 17
I have the following within a SELECT statement:

Expand|Select|Wrap|Line Numbers
  1. :
  2.  
  3.  
  4. AnnualRP = sum(CASE WHEN Original.CampCode like '%u%' 
  5. AND(Original.CompletedCode = 24 OR Original.CompletedCode = 25) 
  6. THEN cast((adprem)*12 as money)
  7. WHEN Original.CampCode like '%u%' 
  8. AND(Original.CompletedCode <> 25 AND Original.CompletedCode <> 24) THEN 0 
  9. ELSE cast((Price)*12 as money) END) 
  10. + (Select cast(sum(annualrp) as money) as annualrp from tbl_obmi_manualsales where date = original.calldate and campcode = original.campcode and democode = original.democode) ....
  11.  
  12.  
...so essentially what I am doing is firstly creating the figure for AnnualRetailPrice (AnnualRP) using the case statement ("if it is an upgrade campaign and a sale sum the additional premium else take the full price); then adding on any figures for manual sales (sum(annnualrp) from tbl_obmi_manualsales.

To me this seems logical, however, every row has 'null' in the resultant dataset.

I have also tried joining the table on and adding onto the end "+ ManualSales.annualRP", but this still returns no records.

Am I unaware of some addition rule here or some other rule?

The query works and gives figures when the addition is taken off, it's just when it's tacked onto the end it gives null values.

Any ideas or pointers please?!

Thanks

J
Apr 17 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
I have the following within a SELECT statement:

Expand|Select|Wrap|Line Numbers
  1. :
  2.  
  3.  
  4. AnnualRP = sum(CASE WHEN Original.CampCode like '%u%' 
  5. AND(Original.CompletedCode = 24 OR Original.CompletedCode = 25) 
  6. THEN cast((adprem)*12 as money)
  7. WHEN Original.CampCode like '%u%' 
  8. AND(Original.CompletedCode <> 25 AND Original.CompletedCode <> 24) THEN 0 
  9. ELSE cast((Price)*12 as money) END) 
  10. + (Select cast(sum(annualrp) as money) as annualrp from tbl_obmi_manualsales where date = original.calldate and campcode = original.campcode and democode = original.democode) ....
  11.  
  12.  
...so essentially what I am doing is firstly creating the figure for AnnualRetailPrice (AnnualRP) using the case statement ("if it is an upgrade campaign and a sale sum the additional premium else take the full price); then adding on any figures for manual sales (sum(annnualrp) from tbl_obmi_manualsales.

To me this seems logical, however, every row has 'null' in the resultant dataset.

I have also tried joining the table on and adding onto the end "+ ManualSales.annualRP", but this still returns no records.

Am I unaware of some addition rule here or some other rule?

The query works and gives figures when the addition is taken off, it's just when it's tacked onto the end it gives null values.

Any ideas or pointers please?!

Thanks

J

Would you mind posting the entire query?

-- CK
Apr 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.