Author |
Topic |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2012-02-05 : 11:04:27
|
hibased on this example.Select ItemID, ProdName from table1unionSelect ProdID, ItemName from table1order by ItemNameI need to because of the nature of the product nameHow can i achieve an order by on the ItemName? Thanks a lotThanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-05 : 11:22:25
|
so after all itemNames ProdName should come?select ID,Valfrom(Select ItemID AS ID, ProdName AS Val,1 as Ord from table1unionSelect ProdID, ItemName,0 from table1)tOrder by Ord,Val ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2012-02-05 : 11:49:27
|
Sorry, I made a mistake on the SQL statement. It should be Select ItemID, ProdName from table1unionSelect ProdID, ItemName from table2order by ItemNameThanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-05 : 12:12:39
|
[code]select ID,Valfrom(Select ItemID AS ID, ProdName AS Val,1 as Ord from table1unionSelect ProdID, ItemName,0 from table2)tOrder by Ord,Val[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2012-02-05 : 12:14:27
|
Thanks |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-05 : 12:52:02
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2012-02-05 : 20:53:19
|
hiI am not able to get the results. This is my resultsetID PrtID Name1 NULL A2 NULL B3 2 C4 2 D5 NULL E1003 1 A41011 1 A51013 1 A61016 1 A1The id from 1 to 5 is based on the first union query while the id from 1003 to 1016 is based from the second query.As you notice, A4,A5,A6,A1 are not sorted by text. How do i make the second query to be sorted so that i would get this. ThanksID PrtID Name1 NULL A2 NULL B3 2 C4 2 D5 NULL E1016 1 A11003 1 A41011 1 A51013 1 A6 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-06 : 10:07:22
|
sorry this is different from what you posted before. you've an additional column. can you show the query used for this?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|