CHECKING DIFFERENCE BETWEEN TWO COLUMNS

الإجابة CHECKING DIFFERENCE BETWEEN TWO COLUMNS

  • Friday, November 30, 2012 9:32 PM
     
     

    HI

    Please help 

    I have Data like this in a Table (About 9 million records) ALL DATA  is exactly in the same Format

    How to compare two columns in the same table and if matched  indicate it as Yes if not No.

    MONTH_01        MODIFIED
    --------------------------------------------------
    8.000000000000000 8.000000000000000
    24.000000000000000 24.000000000000000
    -1.000000000000000 -2.000000000000000

    0.000000000000000 1.000000000000000 

    I want in this format

    MONTH_01        MODIFIED                 INDICATE
    --------------------------------------------------
    8.000000000000000 8.000000000000000         YES
    24.000000000000000 24.000000000000000        YES 
    -1.000000000000000 -2.000000000000000        NO
    0.000000000000000 1.000000000000000         YES

    Regards

    KODI

All Replies

  • Friday, November 30, 2012 9:44 PM
    Moderator
     
     Answered Has Code

    Hi, you could use a CASE statement in your SELECT.  Something like:

    select Month_01, Modified, CASE WHEN Month_01 = Modified THEN 'Yes' ELSE 'No' END AS Indicate
    from Table1

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.


  • Friday, November 30, 2012 9:44 PM
     
     
    What is the exact datatype for the two columns?

    "Premature optimization is the root of all evil." - Knuth

    If I provoked thought, please click the green arrow

    If I provoked Aha! please click Propose as Answer

  • Friday, November 30, 2012 9:45 PM
    Moderator
     
     Answered Has Code

    You can use a CASE Expression to check whether the two columns are equal in a SELECT statement or you can UPDATE your table similarly.

    You may need to consider NULL values for these columns if they are nullable columns.

    SELECT MONTH_01,MODIFIED,CASE
                               WHEN MONTH_01 = MODIFIED THEN 'Yes'
                               ELSE 'No'
                             END AS INDICATE
    FROM   yourtable 


  • Friday, November 30, 2012 9:50 PM
     
     
    THANK you SAM
  • Friday, November 30, 2012 9:50 PM
     
     
    Thank You  Jingyang Li