Order by is not working

  • Order by is not working because table itself contain "order" column's name but i cant chage column name

    CREATE TABLE dbo.LU_OVERVIEW_CONTROL_PAGE

    (

    cvnt_page_stub dbo.ut_stub NOT NULL,

    overview_control_id smallint NOT NULL,

    status_id_list dbo.ut_long_description NOT NULL,

    [order] smallint NOT NULL

    ) ON [primary]

    and query is

    select * from LU_OVERVIEW_CONTROL_PAGE locp

    order by locp.order

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • You are using user defined data types.

    I changed the table structure and then inserted the records. Nothing seem to be wrong. Can you please give some details;

    CREATE TABLE dbo.LU_OVERVIEW_CONTROL_PAGE

    (

    cvnt_page_stub int NOT NULL,

    overview_control_id smallint NOT NULL,

    status_id_list varchar(100) NOT NULL,

    [order] smallint NOT NULL

    ) ON [primary]

    --and query is

    Insert into dbo.LU_OVERVIEW_CONTROL_PAGE

    Select 1,1,'A',1 Union All

    Select 1,1,'A',2 Union All

    Select 1,1,'A',3 Union All

    Select 1,1,'A',4

    select * from LU_OVERVIEW_CONTROL_PAGE locp

    order by locp.[order] Desc

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • Since the column name is a reserved word, you need to enclose it in [] every time you reference it.

    select cvnt_page_stub, overview_control_id, status_id_list, [order]

    from dbo.LU_OVERVIEW_CONTROL_PAGE locp

    order by [order]

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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