Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2005, 06:17 PM
Registered User
 
Join Date: Oct 2005
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


 
Old October 27th, 2005, 06:22 PM
Registered User
 
Join Date: Oct 2005
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.

 
Old November 8th, 2005, 01:21 AM
Authorized User
 
Join Date: Feb 2005
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





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





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