Order By Problem

  • Hi,

    I have the inputs in the following order.

    CREATE TABLE #ABC

    (

    clientname VARCHAR(30)

    )

    INSERT INTO #ABC

    SELECT 'UTA01' UNION ALL

    SELECT 'UTA02' UNION ALL

    SELECT 'TTA01' UNION ALL

    SELECT 'TTA02' UNION ALL

    SELECT 'DTA01' UNION ALL

    SELECT 'DTA02'

    And the Desired Output is

    UTA01

    TTA01

    DTA01

    UTA02

    TTA02

    DTA02

    in only one query

  • SELECT clientname

    FROM #ABC

    ORDER BY SUBSTRING(clientname,3,3)

    ,SUBSTRING(clientname,1,2)DESC

    -Vikas Bindra

  • what are you rules for ordering?

    You really need a primary key / clustered index to define the order

  • You can refer to BOL / MSDN for rules/ in how you can use the order by clause.

    Abhijit - http://abhijitmore.wordpress.com

  • Thanks vikas.

    Its working fine..

  • Thanks Abhijit,.. I will check the rules once.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply