Start with function

  • I have a list of records in a table of Locations,

    Africa, ASIA, Europa, America and would like to select and order by locations,

    i would like to always start with ASIA since its the home location and the rest "order by Asc". how do i go about this.

    Regards

  • Use a CASE expression in the ORDER BY clause.

    DECLARE @Locations TABLE (

    LocationName varchar(10)

    )

    INSERT INTO @Locations VALUES('Africa')

    INSERT INTO @Locations VALUES('ASIA')

    INSERT INTO @Locations VALUES('America')

    INSERT INTO @Locations VALUES('Europa')

    SELECT *

    FROM @Locations

    ORDER BY CASE LocationName WHEN 'ASIA' THEN 0 ELSE 1 END, LocationName

    Hope this helps

    Gianluca

    -- Gianluca Sartori

  • Thnaks so much. It works .

    Regards

  • You're welcome.

    Glad I could help

    -- Gianluca Sartori

Viewing 4 posts - 1 through 3 (of 3 total)

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