Discussion:
PLease help with a query
(too old to reply)
Haas C
2012-01-31 00:56:19 UTC
Permalink
I posted this before and got the wrong answer - can someone please
help?:
-------

Hello all!

I'm a newbie with SQL and I've run into a wall here trying to figure
the best way to write a query in SQL Server 2008 to get my desired
results. Here's the scenario:


I have a table named tblProfit. There are only three fields in the
table: ROL, Year, and NetProfit - here's what I need to achieve:

I want the query to return aggregated values of NetProfit by Year
based on the following ROL ranges:


0% to 25%
25.1% to 50%
50.1% to 100%


I have four Years worth of data in the table: 2008, 2009, 2010, and
2011. I'd like my output show the ranges above - so something like
this (the first row below represents output table headers:


ROL_1, ROL_2, Year, NetProfit
0%, 25%, 2008, 1000000
25.1%, 50%, 2008, 4000000
50.1%, 100%, 2008, 3500000
etc. for each of the years (Also, ROL field has everything in
decimals, i.e. 0.25 is 25% but I can make that formatting once I have
the output)


Any and all help would be appreciated - thanks!
Bob Barrows
2012-01-31 04:12:12 UTC
Permalink
Post by Haas C
I posted this before and got the wrong answer - can someone please
-------
If you don't provide the information requested in your first thread, why do
you expect us to be able to help you given the same incomplete information
posted originally?

Again:
If you want a tested solution, you should post:

o CREATE TABLE statements for your table.
o INSERT statement with sample data.
o The desired result given the sample.
o Which version of SQL Server you are using. - yes, I know you already gave
us this - SQL 2008, thank you
If you don't know how to generate the scripts needed to provide that
information, see
http://www.karaszi.com/SQLServer/info_generate_script.asp

Please go back to the original thread to post the requested information.
There was no point in starting a new one.

Loading...