display order by houseno

  • i have table house no like this below coloum.........

    house_no

    3-13-10

    3-13-200/a

    3-13-450/a

    3-13-1345/b

    3-13-12

    3-13-4

    3-13-567/c

    3-13-832/a

    3-13-943

    i want table like this....

    3-13-4

    3-13-10

    3-13-12

    3-13-200/a

    3-13-450/a

    3-13-567/c

    3-13-832/a

    3-13-943

    3-13-1345/b

    pl write the quarie..................

  • its a cross post

    you have already put same question earlier here http://www.sqlservercentral.com/Forums/Topic1511010-3077-4.aspx

  • it shows error like

    Msg 245, Level 16, State 1, Line 1

    Conversion failed when converting the nvarchar value '17-280' to data type int.

  • One, reposting on a new thread isn't going to get you different answers.

    Two, on your original thread, please post the code you are using. You should also take the time to read the first article I reference below in my signature block. It will walk you through what you need to post and how to post it to get the best possible answer to your question.

  • The short answer is that you should re think your database.

    From the question it is clear that the field is storing at least three separate entities:

    Sector (3-13) - varchar

    PropertyID (414) - int

    Sub Property ID (/a) - varchar

    To do the sorting that you want, you will need to split the value into three, sort by the middle and last columns and then recombine the values. Longer term it would probably be better to store these permanently rather than split and recombine each time.

    If you can't change the existing columns, you could possibly add computed columns to the existing table, or create a lookup table with Create, Update and Delete triggers on the existing table. Failing that, a table function would do it, but performance may take a hit, depending on the size of the dataset being processed.

  • Each one of your five current threads

    select quarie between houseno ..........

    select house_no order

    select only up to first '-' only

    display order by like 1,2,3,4,5...............plz write quarie

    display order by houseno

    relate to the same issue. Help us and you will help yourself. Please provide a sample data set which is properly representative of your data. Your data doesn't all look like "3-9-55". If it did, any one of several solutions already posted would work just fine.

    Is "3-9-55" just a Hyderabad house number or is it three data elements combined into one?


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • If you have to keep the data this way, maybe can parse the hourse_no, then order by different parts.

    SELECT

    CAST(SUBSTRING(hourse_no,1,CHARINDEX('-',hourse_no)-1) AS INT),

    CAST(SUBSTRING(hourse_no,CHARINDEX('-',hourse_no)+1,2) AS INT),

    ...

    FROM #temp

    ORDER BY

    CAST(SUBSTRING(hourse_no,1,CHARINDEX('-',hourse_no)-1) AS INT),

    CAST(SUBSTRING(hourse_no,CHARINDEX('-',hourse_no)+1,2) AS INT),

    ...

  • ChrisM@home (12/15/2013)


    Each one of your five current threads

    select quarie between houseno ..........

    select house_no order

    select only up to first '-' only

    display order by like 1,2,3,4,5...............plz write quarie

    display order by houseno

    relate to the same issue. Help us and you will help yourself. Please provide a sample data set which is properly representative of your data. Your data doesn't all look like "3-9-55". If it did, any one of several solutions already posted would work just fine.

    Is "3-9-55" just a Hyderabad house number or is it three data elements combined into one?

    :w00t: now these are some threads ....

  • twin.devil (12/16/2013)


    ChrisM@home (12/15/2013)


    Each one of your five current threads

    select quarie between houseno ..........

    select house_no order

    select only up to first '-' only

    display order by like 1,2,3,4,5...............plz write quarie

    display order by houseno

    relate to the same issue. Help us and you will help yourself. Please provide a sample data set which is properly representative of your data. Your data doesn't all look like "3-9-55". If it did, any one of several solutions already posted would work just fine.

    Is "3-9-55" just a Hyderabad house number or is it three data elements combined into one?

    :w00t: now these are some threads ....

    501's, mate. Best in the world ๐Ÿ˜›

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 9 posts - 1 through 8 (of 8 total)

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