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
 General SQL Server Forums
 New to SQL Server Programming
 Is It Possible - Select Query - Order By ...?

Author  Topic 

paramu
Posting Yak Master

151 Posts

Posted - 2009-10-03 : 02:32:05
I have a select query
"Select * from it_master order by it_description"

giving the o/p like the below
------------------------------------it_description
------------------------------------
CABLE LUGS 1.5 MM -FLAT TYPE
CABLE LUGS 10 MM2 x 10 MM ALUMMINIUM
CABLE LUGS 100 MM x 10 MM HOLE
CABLE CONNECTOR 10 MM
CABLE LUGS 2 MM2 U TYPE
CABLE LUGS 20 MM2 V TYPE
CABLE LUGS 3 MM2 RING TYPE

Is it possible to make the order like the below?
------------------------------------it_description
------------------------------------
CABLE CONNECTOR 10 MM
CABLE LUGS 1.5 MM -FLAT TYPE
CABLE LUGS 2 MM2 U TYPE
CABLE LUGS 3 MM2 RING TYPE
CABLE LUGS 10 MM2 x 10 MM ALUMMINIUM
CABLE LUGS 20 MM2 V TYPE
CABLE LUGS 100 MM x 10 MM HOLE

Thanks



Paramu @ PARANTHAMAN

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-03 : 02:52:36

select oringinal_Data,substring(data,patindex('%[0-9]%',data),charindex(' ',data)) from
(
select it_descriptionas oringinal_it_description,substring(it_description,patindex('%[0-9]%',it_description),len(it_description)) as it_description from it_master
) as t

order by cast(substring(it_description,patindex('%[0-9]%',it_description),charindex(' ',it_description)) as decimal(12,0))



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-10-03 : 06:07:45
Can you pls. elaborate? My table fields are

select it_code,it_description,it_specify,it_details,ut_measure from it_master order by it_description

Paramu @ PARANTHAMAN
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-03 : 08:17:57
quote:
Originally posted by paramu

Can you pls. elaborate? My table fields are

select it_code,it_description,it_specify,it_details,ut_measure from it_master order by it_description

Paramu @ PARANTHAMAN


Did you try the code I posted?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

paramu
Posting Yak Master

151 Posts

Posted - 2009-10-03 : 11:41:54
Thankyou Madhivanan.
I tried, it says invalid column name original_data,Data

Paramu @ PARANTHAMAN
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-05 : 01:52:19
select oringinal_Data,substring(data,patindex('%[0-9]%',data),charindex(' ',data)) from
(
select it_description as oringinal_it_description,substring(it_description,patindex('%[0-9]%',it_description),len(it_description)) as it_description from it_master
) as t

order by cast(substring(it_description,patindex('%[0-9]%',it_description),charindex(' ',it_description)) as decimal(12,0))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -