Getting results in the same order as query

  • We have a table being used for Translation from English into Italian. It has a column for English and a column for Italian.

    There are no indexes on the table, but the data has been entered in alphabetical order.

    Is there any way I can get it to supply the output in the same order as it was requested ?

    i.e. when I specify UK in ('Jan','Feb','Mar','Apr') - I get that back and not Apr, Feb, Jan, Mar ?

    I have tried putting it in a cursor, but I still get the alpha orders.

    Any ideas would be appreciated.

    June Johnston

    June.Johnston@hrplc.co.uk

    SQL DBA

    Hogg Robinson

  • If you want the order guaranteed you'll have to add an order by.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Hi June

    Andy's right you need some sort of order by clause or possibly a clusterd index, but I can't see how that would help in the example you've quoted.

    Is it just date names you're storing in this table or more, I've done some work on language stuff (French/English). Could you give a little more detail of your prob'

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • The table contains various languages with a phrase in english, to be translated into various languages (including Italian, German, French etc).

    It is storing all kinds of phrases not just dates.

    The aim is to request the data in english and we return one of the other languages.

    Another example would be to supply 'Hotel name','Arrive date','Length of stay' from a VB SQL query and then have the same values returned by in the new language - in the same order as they were requested.

    June Johnston

    SQL DBA

    June.Johnston@hrplc.co.uk

  • You can order by a column not included in your query.

    Steve Jones

    steve@dkranch.net

  • I guess you're not returning the values in correct grammatical order for the language. Steve is right, all you need to do is create a column (probably numeric) giving a phrase a unique identity (don't mean an identity column by the way). Then if you give the same phrase the same id in all your languages. You can at least establish the order they were requested.

    The fun part comes when the phrases are not requested in strict ascending or descending order. I don't know of a sort that would handle that, maybe there are Guru's out there who do.

    I think you will have to have some process either in the calling VB program which determines the ID sequence of the incoming phrases and then assembles a return to the user by working through the recordset of returned translations placing them in the same ID sequenece.

    In short determine the calling sequenece, select the translations, get the id's from the result set and assemble an output string by taking the values from the recordset an popping them into the string in the same ID sequence.

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • Still not sure why you'd care - better to implement better code that works with the data so that the positioning doesnt matter.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Hi Andy, yup I agree however I thinks June's problem is a little complexe. Her example is

    'Hotel name','Arrive date','Length of stay'

    And the corresponding translation might be Nom D'Hotel, Jour D'arrive, Combien Des Jours.

    If these have been eneterd in Alphabetical order then the records in the database would be

    Arrive Date

    Hotel Name

    Length Of Stay

    And the French

    Combien Des Jours

    Jour D'arrive

    Nom D'Hotel

    So if the translation is to be for 'Hotel name','Arrive date','Length of stay' you can't use alphabetic sorting or even a straight ascending or descending sort to match the right translation to the phrase in the sequence the phrases were entered.

    The only way I've really found translation to work is by the use of resource files in the VB (Delphi etc.) programs

    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961


    I have found it is possible to please all of the people all of the time if you do exactly what they want. Harold Macmillan 1961

  • Thanks for all your help folks..my boss came up with a solution using a temp table and a user defined function to get round the problem.

    June Johnston

    june.johnston@hrplc.co.uk

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

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