Results 1 to 2 of 2

Thread: query help

  1. #1
    Join Date
    Mar 2004
    Posts
    139

    Unanswered: query help

    I have a query:

    select
    account,
    name,
    balance,
    month,
    year
    from
    data_table
    where
    month in (8, 11) and year = 2005 and
    account in (select account from catalog.dbo.account_info)

    That gives a result (but with thousands of records, 2 for each account):

    ACCOUNT NAME BALANCE MONTH YEAR
    12345678 SMITH, JOE 100000.0000 8 2005
    12345678 SMITH, JOE 110000.0000 11 2005

    What I'm trying to do is come up with a query that returns a single record that shows the 'BALANCE' difference between the two months for each account. Using info from the same table...

    So something like:

    ACCOUNT NAME DIFFERENCE
    12345678 SMITH, JOE 10000.000

    Can anyone help me out? Thanks...
    Thanks,
    Bill

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    How do you know what months you will be looking at in any given run? Assuming you want to literally compare months 8 and 11 for year 2005, you could code this fairly simply.

    The problem I'm having is that I don't understand enough of your business requirements to really know how to attack the problem. Once you explain that, the solution might be a bit complicated, but it isn't likely to be hard.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •