Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting rows

Status
Not open for further replies.

cihatkarli

Programmer
May 22, 2007
18
0
0
TR
i have a 4 cell table

example

1 AAAA CCCC DDDD
2 CCCC KKKK BBBB
3 DDDD NNNN AAAA

i want every line's output sorted alpabethically

like this.

1 AAAA CCCC DDDD
2 BBBB CCCC KKKK
3 AAAA DDDD NNNN


tried to do with excel but no luck.
 
Hi

The SQL databases usually can sort records. I never heard about one able to sort fields.

What you want seems easier to solve in the application which queries the data.

What do you try to accomplish more exactly ?

Feherke.
 
what a wacky request

caution: this is untested, and if it doesn't work, you can surely figure out the logic yourself, yes?
Code:
select id
     , case when colA <= colB
             and colA <= colC
            then colA
            when colB <= colC
            then colB
            else colC       as col_1  
     , case when colA <= colB
             and colB <= colC
            then colB
            when colB <= colC
             and colC <= colA
            then colC
            else colA       as col_2  
     , case when colA <= colB
             and colB <= colC
            then colC
            when colB <= colC
             and colC <= colA
            then colA
            else colC       as col_3
  from daTable

r937.com | rudy.ca
 
it's a quick job that my boss wanted.

r397 your query gives an syntax error.
 
Hi

Try to close the [tt]case[/tt]s :
Code:
select id
     , case when colA <= colB
             and colA <= colC
            then colA
            when colB <= colC
            then colB
            else colC
            [red]end[/red]             as col_1  
     , case when colA <= colB
             and colB <= colC
            then colB
            when colB <= colC
             and colC <= colA
            then colC
            else colA
            [red]end[/red]             as col_2  
     , case when colA <= colB
             and colB <= colC
            then colC
            when colB <= colC
             and colC <= colA
            then colA
            else colC
            [red]end[/red]             as col_3
  from daTable

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top