Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re-select if ISNULL (SQL Server)

    Hi,
    can you please, help me with this query?
    I need to write this logic into sql statement, Access would be fine. Thanks

    If ISNULL(Select CoID,INDID,Address from XXX
    where INDID = '333')
    then (Select CoID,INDID,Address from XXX
    where CoID = '222')

    I don't know where to place it.

    I am using Windows XP, Crystal Reports 9.0 with SQL Server

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

    Re: Re-select if ISNULL (SQL Server)

    What do you mean by ISNULL? That the query

    Select CoID,INDID,Address from XXX
    where INDID = '333'

    returns no records, or that all fields returned in this query are null (blank), or that at least one of the fields is null?

  3. #3
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Re-select if ISNULL (SQL Server)

    The result of the query is Null - it doesn't bring anything.
    So I want to search by another criteria/parameter.
    Thanks

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

    Re: Re-select if ISNULL (SQL Server)

    And is there an "Else" part to your If ... Then? In other words, what should happen if

    Select CoID,INDID,Address from XXX
    where INDID = '333'

    does return records? Perhaps you want to return those, but you don't say so in your post.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Re-select if ISNULL (SQL Server)

    If first half brings record - I want THAT one, sure...if not, than I will settle for second portion.

    Thanks

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

    Re: Re-select if ISNULL (SQL Server)

    The following will work in Access. In SQLServer there are other ways to do this, but I cannot help you with that. It is rather artificial, and probably very inefficient for large tables.
    <code>
    SELECT CoID, INDID, Address
    FROM XXX
    WHERE INDID=IIf(DCount("*","XXX","INDID='333'"),"333","z zzzz") OR
    ColID=IIf(DCount("*","XXX","INDID='333'"),"zzzzz", "222")
    </code>
    Here, "zzzzz" is a value that doesn't occur in either INDID or ColID.

  7. #7
    5 Star Lounger
    Join Date
    Jan 2005
    Posts
    614
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Re-select if ISNULL (SQL Server)

    THANKS A LOT!!!!

Posting Permissions

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