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 |
jackimo
Starting Member
1 Post |
Posted - 2008-03-13 : 08:43:19
|
I am trying to 'combine' the output of fields into one column.I have rows in a table like thisCUSTOMER1 CUSTOMER2 CUSTOMER3SMITH JONES WILSONEDWARDS SMICKS SMOKESSMITH TODD HELPI would like to see a distinct list of customer fields where the name is LIKE (SM%)So the output would beSMITH (notice this is distinct)SMICKSSMOKESAny ideas or comments would be greatly appreciated - Thanks! |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-03-13 : 08:46:49
|
[code]select distinct customer from(Select customer1 as customer from table where customer1 LIKE 'SM%'union allSelect customer2 as customer from table where customer2 LIKE 'SM%'union allSelect customer3 as customer from table where customer3 LIKE 'SM%') temp[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-13 : 08:54:13
|
Depending on the number of records, this can be an alternaiveSELECT Customer1 AS Customer FROM Table1 WHERE Customer1 LIKE 'SM%'UNIONSELECT Customer2 FROM Table1 WHERE Customer2 LIKE 'SM%'UNIONSELECT Customer3 FROM Table1 WHERE Customer3 LIKE 'SM%' E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|