CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2005
    Posts
    178

    help with a query

    i wrote a scalare function-

    select name,id

    from tableName

    where function1(id) / function2(id)>100

    but sometimes function2 returns zero so im getting a divide by zero exception.

    how can i solve this problem?

    thanks in advanced

  2. #2
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Re: help with a query

    add a condition to check that first - if function2 returns 0 and apply an AND condition between 2 where clause conditions.. if the first comes out false.. it should probably not check the second condition.. and hence ... see if that works..

    what db system are you on? Hope this helps. Regards.

  3. #3
    Join Date
    May 2005
    Posts
    178

    Re: help with a query

    but how can i add a condition to a "where" ?
    im using sql-server

  4. #4
    Join Date
    Aug 2002
    Location
    Kerala
    Posts
    1,183

    Re: help with a query

    Quote Originally Posted by ppl1
    but how can i add a condition to a "where" ?
    im using sql-server
    Use two queries. First do "select function2(id) from TableName" test the value. If the value returned is zero do not continue to query "select name,id from tableName where function1(id) / function2(id)>100".

  5. #5
    Join Date
    May 2005
    Posts
    178

    Re: help with a query

    ok thanks for the help

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

Featured