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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sorting values record wise in a table

Author  Topic 

jayram11
Yak Posting Veteran

97 Posts

Posted - 2011-05-20 : 09:50:40
Hi

create table #sort(
PR varchar(5),
val1 varchar (2),
val2 varchar (2),
val3 varchar (2),
)

insert into #sort(PR , val1, val2, val3)
select 2345X , ‘AU’, ‘ZZ’, ‘BK’ union all
select 2345Y , ‘AU’, ‘KX, ‘BK’ union all
select 2345Y , ‘AU’, ‘BZ, ‘BK’ union all
select 2345Y , ‘XY’, ‘ZZ’, ‘BK’ union all
select 2345A , ‘AB’, ‘AA’, ‘BK’ union all
select 2345A , ‘AU’, ‘ZZ’, ‘BK’ union all
select 2345A , ‘AU’, ‘ZZ’, ‘BK’ union all
select 2345B , ‘AU’, ‘ZZ’, ‘’ union all
select 2345B , ‘AU’, ‘’, ‘BK’ union all
select 2345B , ‘AU’, ‘ZZ’, ‘BK’ union all
select 2345C, ‘AU’, ‘’, ‘AA’ union all
select 2345C , ‘AU’, ‘ZZ’, ‘BK’ union all
select 2345C , ‘’, ‘ZZ’, ‘BK’ union all
select 2345D , ‘AU’, ‘ZZ’, ‘’

this is kind of unique so was wondering i anyone could help me

i want to sort the VAL variables horizontally in alphabetical order

if it is ‘’, ‘ZZ’, ‘BK’, i need to sort to ‘BK’, ‘ZZ’, ''

if it 'AB', 'AA', 'AC', i need to sort to 'AA', 'AB', 'AC'

empty values ('') should always be in last variable - Val3
All help is appreciated...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-20 : 10:33:03
Give this a try: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=146143
Go to Top of Page

jayram11
Yak Posting Veteran

97 Posts

Posted - 2011-05-20 : 11:57:54
Thanks!!!
Go to Top of Page
   

- Advertisement -