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.0000000000000000.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 YESRegards
KODI
All Replies
-
Friday, November 30, 2012 9:44 PMModerator
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)
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.- Edited by Samuel Lester - MSFTMicrosoft Employee, Moderator Friday, November 30, 2012 9:45 PM
- Marked As Answer by KODI_KODI Friday, November 30, 2012 9:50 PM
-
Friday, November 30, 2012 9:44 PMWhat 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 PMModerator
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
- Edited by Jingyang LiModerator Friday, November 30, 2012 9:47 PM
- Marked As Answer by KODI_KODI Friday, November 30, 2012 9:49 PM
-
Friday, November 30, 2012 9:50 PMTHANK you SAM
-
Friday, November 30, 2012 9:50 PMThank You Jingyang Li

