Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    126

    Unanswered: IF in T-SQL Column Expression

    PLEASE PLEASE PLEASE HELP ME!!! Sorry, but this has been driving me crazy all day and I'm about to kill someone or something.

    I have a report in an Access Data Project that I want to group in two groups:

    1. Previous Activity - Records with doc_date < @StartDate
    2. Current Activity - Records with doc_date >= @StartDate

    Since Access's grouping features are faily me, I have decided to simply add a column to to the query I am using as the recordsource for my report that simply evaluates to 0 if the record meets condition 1. and evaluates to 1 if it meets condition 2. I will then group my report on that column to get exactly the two groups I want.

    I have posted this here instead of in the Access forum because Access Data Projects use T-SQL, and I am looking for T-SQL syntax to get my column into my query. I already know how to group by the column.

    I essentially want the equivalent of IFF(doc_date < @StartDate,0,1) but T-SQL obviously doesn't handle JET/VB operators, so if someone could PLEASE help me with this simple question by telling me what the SELECT statement might look like to add this column to my query, I'll be your best friend!

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    select columnA, columnB, (CASE WHEN columnB < @doc_date THEN -1 ELSE 1 END) As "TYPE"
    from table
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Feb 2004
    Posts
    126
    Thank You! I eventually figured it out, but I don't think it was very explicitly stated in either of the 1500 page Access 2003 books I just read, grrrrr.

Posting Permissions

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