Database & SQL

Moderators: None (Apply to moderate this forum)
Number of threads: 1174
Number of posts: 2221

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need to control field placement in output Posted by CyBear0099 on 29 Oct 2004 at 9:06 AM
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 <account #> Customer <customername> Status <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?

Report
Re: Need to control field placement in output Posted by infidel on 1 Nov 2004 at 8:10 AM
: 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 <account #> Customer <customername> Status <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 into some data structure which would allow you to reference individual fields by name in whatever order you require.


infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.