Results 1 to 4 of 4
  1. #1
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Count in SQL (SQL)

    I am trying to create a count of Service Requests that were closed with 10 days and SQL is stating "Line 1: Incorrect syntax near '<'."

    I am banging my head against a wall. I got this to work in Access but SQL doesn't like it

    select iincidentid, Count(IIf(datediff(dd,dtinsertdate,dtupdatedate)<= 10 And datediff(dd,dtinsertdate,dtupdatedate)>=0,1)) AS Within10Days
    Jerry

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Count in SQL (SQL)

    As far as I know, SQL Server doesn't have IIf - you can use CASE WHEN instead.

  3. #3
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Count in SQL (SQL)

    <img src=/S/blowup.gif border=0 alt=blowup width=60 height=60> thanks
    Jerry

  4. #4
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Count in SQL (SQL)

    Thanks Hans

    That was a wake up call, the answer is

    select
    iincidentid,
    'Within10Days' =
    CASE
    WHEN datediff(day,dtinsertdate,dtupdatedate)<=10 And

    datediff(day,dtinsertdate,dtupdatedate)>=0 THEN '1'

    ELSE '0'
    END,
    vchProductName

    ....
    Jerry

Posting Permissions

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