Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    India
    Posts
    109

    Unanswered: Help needed in a Query

    I have a query that need to do something like this.


    About the data:
    ---------------
    I have a rules table which has got all the rules, and a log table that has the logs which says whether the rules are satisfied or not over a point of time.


    select rules, sum(decode(status,'pass','1')) as passed, sum(decode(status,'fail',1)) as failed from rulestable,logstable where rulestable.logid=logstable.id

    My expected Output
    ---------------------------------
    Rule1 passed= 10 failed=12
    Rule2 passed=11 failed=15


    But i donot have decode() function in mssql nor can I use IF ELSE here. Can anyone please tell me how this can be implemented here?

    Thanks

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by rexselin
    select rules, sum(decode(status,'pass','1')) as passed, sum(decode(status,'fail',1)) as failed from rulestable,logstable where rulestable.logid=logstable.id

    But i donot have decode() function in mssql nor can I use IF ELSE here. Can anyone please tell me how this can be implemented here?

    Thanks
    Code:
      select rules, 
    sum(CASE status WHEN 'pass' THEN 1 ELSE 0 END) as passed, 
    sum(CASE status WHEN 'failed' THEN 1 ELSE 0 END) as failed 
    from rulestable INNER JOIN logstable ON rulestable.logid=logstable.id
    ANSII Joins used too. HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Aug 2003
    Location
    India
    Posts
    109
    Thanks a lot. It worked.

Posting Permissions

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