Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
Dear all,
i have a table i want to arrange this table value given code formate
 
it is Status table
statuscode	        statusid	StatusCount
 
Just Received	           1	         7
Sent to Engineer	   2	        30
Estimation Not Approved	   4	         2
Under QC	           9	        17
QC Passed	           10	         1
Ready for Delivery	   11          159
Delivered to Customer	   13	       288
Reallocated to Engineer	   17	         1
Sent to HO / RO	           20	         3
Allocated to CSO	   21	         1
Pending For Estimation	   38	        21
Pending For Engineer Estimation	39	40
Pending For Estimation Approval	40	65
Estimation Approved	   41	        17
Pending Payment	           42	        48
Sent To QC Unrepaired	   43	        10
Payment Received	   44	        22
 
how to arreange by statuscode

Just Received
Pending For Estimation
Pending For Engineer Estimation
Pending For Estimation Approval
Estimation Not Approved	
Sent to Engineer
Under QC
QC Passed
Pending Payment	
Payment Received
.
.
.
.
.
.
Posted 8-Oct-12 21:11pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You cannot rearrage these columns. What you can do is you can add a new column DisplayOrder in whic you say the order in which it is to be displayed.
statuscode	        statusid	StatusCount   DisplayOrder
 
Just Received	           1	         7             1
Sent to Engineer	   2	        30
Estimation Not Approved	   4	         2             5
Under QC	           9	        17             6
QC Passed	           10	         1
Ready for Delivery	   11          159
Delivered to Customer	   13	       288
Reallocated to Engineer	   17	         1
Sent to HO / RO	           20	         3
Allocated to CSO	   21	         1
Pending For Estimation	   38	        21              2
Pending For Engineer Estimation	39	40              3
Pending For Estimation Approval	40	65              4
Estimation Approved	   41	        17
Pending Payment	           42	        48
Sent To QC Unrepaired	   43	        10
Payment Received	   44	        22
 

Then when retrieveing You can say
select statuscode from status order by displayorder
  Permalink  
v2
Comments
DINESH K MAURYA at 9-Oct-12 3:23am
   
thank,
trying it.
can be short row if row value like this..
a,b,c,d
arrange it a,c,b,d
Santhosh Kumar J at 9-Oct-12 3:25am
   
I didnt get your question
DINESH K MAURYA at 9-Oct-12 3:41am
   
suppose i have a table name tb
and column name
alphabate
and his rows value like
a
b
c
d
arrange it
a
c
b
d
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Add another column for status code and sort order by status code when select records
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You will need to either add a column which provides the sort order, or write a monolithic CASE statement:
SELECT * FROM MyTable
   ORDER BY
     CASE statuscode
     WHEN 'Just Recieved' THEN 1
     WHEN 'Pending For Estimation' THEN 2
...
     ELSE 9999
     END
I would add the column, myself!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

create new table,
table = ProcessFlow
No   ProcessName
1    Just Received
2    Pending For Estimation
3    Pending For Engineer Estimation
4    Pending For Estimation Approval
5    Estimation Not Approved	
6    Sent to Engineer
7    Under QC
8    QC Passed
9    Pending Payment	
10   Payment Received
.
.
.
 
join your table with processFlow table
like below
select statuscode, statusid, StatusCount
from tbl
left join ProcessFlow on ProcessFlow.ProcessName=statuscode
Order by 
ProcessFlow.No
 
Tips, easy way is in your table statuscode should be numbers and join tables using this nos. and display processname
it will save memory

 
Happy Coding!
Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100