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 |
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-07-27 : 10:52:45
|
helloi have a table structured like thisCREATE TABLE [dbo].[COST]( [ID] [varchar](5) NOT NULL, [LOC1] [varchar](2) NOT NULL, [LOC2] [varchar](2) NOT NULL, [LOC3] [varchar](2) NOT NULLCONSTRAINT [PK_COST] PRIMARY KEY CLUSTERED ( [ID] ASC, [LOC1] ASC, [LOC2] ASC, [LOC3] ASC,)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]) ON [PRIMARY]insert into COST select 'AAAAA' , 'NU' 'KL' , '--'insert into COST select 'AAAAA' , 'RR' 'KL' , 'UE'insert into COST select 'AAAAA' , 'KL' 'KK' , '--'insert into COST select 'AAAAA' , '--' 'KL' , 'KG'insert into COST select 'AABBB' , 'NU' 'KL' , '--'insert into COST select 'AABBB' , 'BA' 'MS' , 'UE'insert into COST select 'AACCC' , 'KK' 'KL' , '--'insert into COST select 'AACCC' , '--' 'UE' , '--'the above is current structure of my tablei want to sort within a record for the LOC1, LOC2 and LOC3 variablesThis is my sorting order NU RR UE MS BA KC KG KK KL -- with highest precedence being NU and lowest being --.so 1st record in above insert statement would remain samethe 2nd would be UE, RR , KL3rd would be KK, KL, -- and so onCan this be done in a function or stored procedure?i am trying to build a update statement but i think it would look big and cumbersomeany help.... Thanks |
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-07-27 : 11:35:28
|
sorry, the second insert would be RR, UE, KL |
 |
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-07-27 : 14:09:28
|
Never mind....i got iti replaced the modifiers with numbers starting from 1 to 10 and used pivot and unpivot to sort it ascendingly and rearrange it....Thanks |
 |
|
|
|
|
|
|