Wade Preston Shearer wrote:
The AS option in an SQL command allows you to rename a field, like this:

select username as user, password as secretcode


Is it possible to rename all of the fields that you pull at once? Here's what I want to do:

I have a table of fields that are all named with the same prefix. I want to rename them as they are pulled from the DB with a different prefix. Is that possible?

I can think of 3 possibilities:

1. Build your query dynamically.
Either query the table structure "DESCRIBE <tablename>", or have a static array of fields. Loop through this mapping definition to build a complex query.

2. Create a view with the desired field names.
CREATE VIEW table_v (new_col1, new_col2, ...) AS SELECT old_col1, old_col2, ... FROM table; This will need to be changed everytime your original table is changed. Then just run all your queries against table_v.

3. Change your result after the query as Craig Jackson already suggested.

--lonnie

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to