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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-11-21 : 17:02:57
|
| I would like to do a count on the result table below:declare @CharacteristicsSecurityTypeNull table(Characteristic varchar(50))insert @CharacteristicsSecurityTypeNullselect 'ABCP'UNION ALLselect 'Bear Bonds'UNION ALLselect 'Bull Bonds'UNIN ALLselect 'Callable Bonds'UNION ALLselect 'Capital'declare @Imports table(ProfileID int, Characteristic varchar(50))insert @Imports select 1, 'Bear Bonds'UNIN ALLselect 2, 'ABCP'UNION ALLselect 3, 'CapitalABCP'UNION ALLselect 4, 'Callable Bonds'UNION ALLselect 5, 'Callable BondsBear Bonds'QUESTION:How do I produce this result table so that I can do a count on Characteristic field?ThanksProfileID Characteristic1 Bear Bonds2 ABCP3 Capital3 ABCP4 Callable Bonds5 Callable Bonds5 Bear BondsI am basically trying to do a count on Characteristic field, so I thought if I produce the result table then I can do a count on it using group by characteristic field. This is what I tried first but it is not correct. I think the issue is to do with the where clauseselect csNull.Characteristic, Count(*)from @Imports i inner join @CharacteristicsSecurityTypeNull csNull on ltrim(rtrim(i.Characteristic)) = ltrim(rtrim(csNull.Characteristic))where --ltrim(rtrim(i.Characteristic)) = 'Credit Facilities' ltrim(rtrim(csNull.Characteristic)) like '%' + ltrim(rtrim(i.Characteristic)) + '%'group by csNull.Characteristicorder by csNull.CharacteristicAny thoughts please?Thanks |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-11-21 : 17:19:04
|
| [code]SELECT i.ProfileID, csNull.CharacteristicFROM @CharacteristicsSecurityTypeNull csNull INNER JOIN @Imports i ON i.Characteristic LIKE '%' + csNull.Characteristic + '%'[/code] |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2008-11-21 : 17:38:22
|
| Thank you |
 |
|
|
|
|
|