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 |
bpuccha
Starting Member
34 Posts |
Posted - 2012-05-28 : 13:42:39
|
Hi,I have a table, contains the below rows0001 001 1 ON -- row10001 001 2 BC ---row20001 001 3 QC ---row30001 001 4 QC ---row4In a procedure first i have to process the above rows based on a variable called province.if province = QC then i have to process 3rd and 4th rows first then i have to process 1st and 2nd rows.How to write these things in a procedure to order the rows based on province? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-28 : 13:55:52
|
something likeSELECT *FROM YourTableORDER BY CASE WHEN Province=@YourParameter THEN 0 ELSE 1 END,RowID ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bpuccha
Starting Member
34 Posts |
Posted - 2012-05-28 : 14:26:38
|
Thanks For th reply..Here is the total sinarioTable Ap_no t_no prov_A0001 001 ONTable Bp_no t_no r_no provi_a0001 001 1 QC - 1st row0001 001 2 ON - 2nd row0001 001 3 BC - 3rd row0001 001 4 QC - 4th row0001 001 5 ON - 5th rowthere are two diff types of lawsCivil law - Is for "QC" provinceComm law - For all other provincesBased on Table A prov_A value we have to decide which rows we have to process first from Table B.In this cases prov_A is ON, so first we have to process all the comm law rows from table B i.eFirst we have to process 2,3,5 then 1 and 4 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-28 : 14:57:59
|
[code]select b.*from TableB bleft join TableA aON a.p_no = b.P_noAND a.t_no = b.t_noAND a.provi_a = b.provi_aorder by b.p_no,b.t_no,case when a.p_no is null then 1 else 0 end asc[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|