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 |
|
KabirPatel
Yak Posting Veteran
54 Posts |
Posted - 2007-03-20 : 06:19:57
|
| Hi,I have 3 tables as follows:TABLE ALandName | LandNumber============================Land A | 10Land B | 20etc....TABLE BCountryName | CountryCode============================England | EGScotland | SCN Ireland | NIetc....TABLE CLandName | CountryCode============================Land A | EGLand A | SCLand B | EGetc...I have been asked to output this data in the following format:LandName | EG | SC | NI===================================================Land A | Yes | Yes | NoLand B | Yes | No | YesWhat is the easiest way of doing this without a cursor?ThanksKabir |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-20 : 06:23:34
|
| SELECT LandName,MAX(case when countrycode = 'eg' then 'Yes' else 'No' end) as [EG],MAX(case when countrycode = 'sc' then 'Yes' else 'No' end) as [SC],MAX(case when countrycode = 'ni' then 'Yes' else 'No' end) as [NI]from tableCgroup by landnameorder by landnamePeter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|