Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sql117
Starting Member
19 Posts |
Posted - 2009-06-25 : 06:43:50
|
| How can i get the result as boolean or(either 1 or 0) if the whole column contains same data or not? The data in table is as follows.Id C2 C31 a b1 a b1 a b2 g h2 k h3 p k3 p kIf i query on this table for ID = 1 then i need to get boolean result whether Columns C2 & C3 contains same data or not.For Example: if i query on Id = 1 then result is Id C2 C31 a b1 a b1 a b Here both columns contain same data. so the result is 1 or yesFor Example : if i query on Id = 2 then Id C2 C32 g h2 k hHere Column C2 contains diff data. So the result is 0 or NOHow i get this through query. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-25 : 06:46:40
|
SELECT ID,CASE WHEN MIN(c2) = MAX(c2) AND MIN(c3) = max(c3) then 1else 0end AS IsSameFROM Table1GROUP BY ID E 12°55'05.63"N 56°04'39.26" |
 |
|
|
sql117
Starting Member
19 Posts |
Posted - 2009-06-25 : 07:15:51
|
Thank you. It works finequote: Originally posted by Peso SELECT ID,CASE WHEN MIN(c2) = MAX(c2) AND MIN(c3) = max(c3) then 1else 0end AS IsSameFROM Table1GROUP BY ID E 12°55'05.63"N 56°04'39.26"
|
 |
|
|
|
|
|