-3

My sql query is..

Select left(Bundle_code,2)
From Item_bundle 
where Item_code='F-4X10AL' and Branch ='KOCHI'
Order by CAST ( Case When ISNUMERIC (left(Bundle_code,2))=1 
                     Then left( Bundle_code,2) 
                     Else -99 End as Int)

The result I got was

result:
2B
6B
3B
7B
8B
9B
10
11

But the order is not correct .Please help me to get a correct order

4

1 回答 1

0

假设你想要 Bundle_code 作为 int (1,2..) + 'B' 你可以写成:

Select  SUBSTRING(Bundle_code,0,CHARINDEX('B',Bundle_code,0) + 1) as Bundle_code
From Item_bundle where Item_code='F-4X10AL' and Branch ='KOCHI'
Order by cast(SUBSTRING(Bundle_code,0,CHARINDEX('B',Bundle_code,0)) as int)
于 2013-10-29T05:56:32.400 回答