Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need to control field placement in output

Sorry, total SQL novice here, and I have a simple problem that does not justify learning a new subject. A search of the message board had some too many hits to wade through.

I have to extract records and use the fields in a Perl script. No matter how my SELECT statement is ordered, the fields in the output seem to appear in the order they were created in the database. Example:
SELECT Customer, Account, Status ..... will yield output of
Account Customer Status

That would be fine, except I cannot ensure the tables are always built the same way in all of the databases. I need to control the output some other way. I could do it in Perl, with a lot of nested loops, but that would be inefficient. Any suggestion?

Comments

  • infidelinfidel Posts: 2,900Member
    : Sorry, total SQL novice here, and I have a simple problem that does not justify learning a new subject. A search of the message board had some too many hits to wade through.
    :
    : I have to extract records and use the fields in a Perl script. No matter how my SELECT statement is ordered, the fields in the output seem to appear in the order they were created in the database. Example:
    : SELECT Customer, Account, Status ..... will yield output of
    : Account Customer Status
    :
    : That would be fine, except I cannot ensure the tables are always built the same way in all of the databases. I need to control the output some other way. I could do it in Perl, with a lot of nested loops, but that would be inefficient. Any suggestion?

    That's unusual. SQL results are by definition unordered rows, but the columns should always be returned in the order you specify. That's so you can reference the fields properly.

    I've never used Perl so I can't help there, but I imagine there must be some way to fetch records [italic]into[/italic] some data structure which would allow you to reference individual fields by name in whatever order you require.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.