Results 1 to 2 of 2

Thread: SQL complication

  1. #1

    Thread Starter
    Frenzied Member met0555's Avatar
    Join Date
    Jul 2006
    Posts
    1,385

    SQL complication

    Hi,

    I think i'm going thru a complicated formula, i'm not sure if there is an easier way to do it.

    I currently have the following code , it works fine
    a Code:
    1. SELECT user, sum((a,b))
    2. from (select * FROM xxxxkmain where net>0 ) as aaa
    3. group by user

    But now wut i wud like to add to my previous query this :
    each user belongs to a department (3 depts in total), so depending on the user dept, i wud like to run different formula(if user is in dep 1 then run formula1.....)
    Code:
    sum((a,b))
    <--- this is the formula part

    Im sure we will need to use an if statement but i'm not sure how to use it in SQL.
    Any tip will e appreciated

    thx

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SQL complication

    You need to give lots more detail here...

    If this is MS SQL server that (a,b) should be a user defined function that can "react" to the user dept and perfrom a different operation.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width