Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 27th, 2005, 06:17 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Within a SELECT do 2 Sum and show only 1

Hi Folks -

I was wondering if anybody knows how to get a single value result from 2 previous calculated results...

Here's my query...
__________________________________________________ ______________________
Select Year(dateeffective) as year1,Month(dateeffective) as month1,count(uwaction) as total1,
Sum(bound_premium) as Bound1,Sum(quoted_premium) as Quoted1,

IIF(Bound1>=Bound1,bound1,quoted1) as new_output


From q_quotes_tbl
Where dateeffective >= '01/01/05' and dateeffective <= '09/20/05' and lob_id=3 and quotetype='new' and
((Cast(bound_premium as numeric) is not null and Cast(bound_premium as numeric) > 0) or
(Cast(quoted_premium as numeric) is not null and Cast(quoted_premium as numeric) > 0))

group by year(dateeffective),Month(dateeffective)
order by year(dateeffective),Month(dateeffective)
__________________________________________________ ______________________
I am having a problem with this line:
IIF(Bound1>=Quoted1,bound1,quoted1) as new_output


What I want to do is to Sum two different fields, and then show me only the greater of the two fields totals.

Any and all help is appreciated.

Thanks.

Ford


Reply With Quote
  #2 (permalink)  
Old October 27th, 2005, 06:22 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This line should actually be:

IIF(Bound1>=Quoted1,bound1,quoted1) as new_output

I posted my test script by mistake, but I still need help.

Thanks.

Reply With Quote
  #3 (permalink)  
Old November 8th, 2005, 01:21 AM
Authorized User
 
Join Date: Feb 2005
Location: Pune, Maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try out this...

SELECT SubQry.*,IIF(SubQry.Bound1>=SubQry.Bound1,SubQry.b ound1,SubQry.quoted1) as new_output
FROM (Select Year(dateeffective) as year1,Month(dateeffective) as month1,count(uwaction) as total1,
    Sum(bound_premium) as Bound1,Sum(quoted_premium) as Quoted1
    From q_quotes_tbl
    Where dateeffective >= '01/01/05' and dateeffective <= '09/20/05' and lob_id=3 and quotetype='new' and
    ((Cast(bound_premium as numeric) is not null and Cast(bound_premium as numeric) > 0) or
    (Cast(quoted_premium as numeric) is not null and Cast(quoted_premium as numeric) > 0))
    group by year(dateeffective),Month(dateeffective)
    order by year(dateeffective),Month(dateeffective)
    ) SubQry

Cheers,
Pooja Falor
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT SUM Top x CassyFrost Classic ASP Basics 3 October 16th, 2007 08:38 AM
XSL:Variable SELECT=sum(condictions) andreracco XSLT 3 August 15th, 2007 08:51 AM
Select Maximum of Sum acko SQL Server 2000 3 June 17th, 2004 11:08 PM
problem with insert, on select data doesn't show pascalgeuze ADO.NET 1 April 24th, 2004 01:50 AM
SELECT SUM syntax... Anubis Access VBA 8 December 15th, 2003 08:04 PM



All times are GMT -4. The time now is 07:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.