Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Compare 3columns from a row with data Null value

Compare 3columns from a row with data Null value

Scheduled Pinned Locked Moved Database
databasetutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Dear all, Please kindly advise my case How to Compare 3columns from a row with data are Null value

    A1 A2 A3 B1 B2 B3 C1 C2 C3
    25 Null Null 25 Null Null 25 Null Null
    Null 20 Null Null 20 Null Null 20 Null

    Select * from Table1 Where (A1=B1 and B1=C1) And (A2=B2 and B2=C2) And (A3=B3 and B3=C3)

    A1 A2 A3 B1 B2 B3 C1 C2 C3
    25 0 0 25 0 0 25 0 0
    0 20 0 0 20 0 0 20 0

    When data value are Null I didn't get result from my query, but after change Null value to 0 (zero) then I have got the result. Could you please advise how to compare data with Null values ? Thanks and best regards

    M S 2 Replies Last reply
    0
    • N Naunt

      Dear all, Please kindly advise my case How to Compare 3columns from a row with data are Null value

      A1 A2 A3 B1 B2 B3 C1 C2 C3
      25 Null Null 25 Null Null 25 Null Null
      Null 20 Null Null 20 Null Null 20 Null

      Select * from Table1 Where (A1=B1 and B1=C1) And (A2=B2 and B2=C2) And (A3=B3 and B3=C3)

      A1 A2 A3 B1 B2 B3 C1 C2 C3
      25 0 0 25 0 0 25 0 0
      0 20 0 0 20 0 0 20 0

      When data value are Null I didn't get result from my query, but after change Null value to 0 (zero) then I have got the result. Could you please advise how to compare data with Null values ? Thanks and best regards

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Read up about ISNULL

      Select * from Table1 Where (ISNULL(A1,'')=ISNULL(B1,'') and ISNULL(B1,'')=ISNULL(C1,'')) And (ISNULL(A2,'')=ISNULL(B2,'') and ISNULL(B2,'')=ISNULL(C2,'')) And (ISNULL(A3,'')=ISNULL(B3,'') and ISNULL(B3,'')=ISNULL(C3,''))

      I hope that copy/paste worked

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N Naunt

        Dear all, Please kindly advise my case How to Compare 3columns from a row with data are Null value

        A1 A2 A3 B1 B2 B3 C1 C2 C3
        25 Null Null 25 Null Null 25 Null Null
        Null 20 Null Null 20 Null Null 20 Null

        Select * from Table1 Where (A1=B1 and B1=C1) And (A2=B2 and B2=C2) And (A3=B3 and B3=C3)

        A1 A2 A3 B1 B2 B3 C1 C2 C3
        25 0 0 25 0 0 25 0 0
        0 20 0 0 20 0 0 20 0

        When data value are Null I didn't get result from my query, but after change Null value to 0 (zero) then I have got the result. Could you please advise how to compare data with Null values ? Thanks and best regards

        S Offline
        S Offline
        sujit0761
        wrote on last edited by
        #3

        Try the below query Select * from Table1 Where (ISNULL(A1,0)=ISNULL(B1,0) and ISNULL(B1,0)=ISNULL(C1,0)) And (ISNULL(A2,0)=ISNULL(B2,0) and ISNULL(B2,0)=ISNULL(C2,0)) And (ISNULL(A3,0)=ISNULL(B3,0) and ISNULL(B3,0)=ISNULL(C3,0)) Use isnull with all the column fields. If the value is null it will take it as zero else it will take the coressponding values. I hope this will help you out!!!!

        N 1 Reply Last reply
        0
        • S sujit0761

          Try the below query Select * from Table1 Where (ISNULL(A1,0)=ISNULL(B1,0) and ISNULL(B1,0)=ISNULL(C1,0)) And (ISNULL(A2,0)=ISNULL(B2,0) and ISNULL(B2,0)=ISNULL(C2,0)) And (ISNULL(A3,0)=ISNULL(B3,0) and ISNULL(B3,0)=ISNULL(C3,0)) Use isnull with all the column fields. If the value is null it will take it as zero else it will take the coressponding values. I hope this will help you out!!!!

          N Offline
          N Offline
          Naunt
          wrote on last edited by
          #4

          Many Thanks to Mycroft Holmes and Sujit0761 Both answer are work in order.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups