Gossamer Forum
Home : Products : DBMan : Customization :

Join two fields to make 'key' field

Quote Reply
Join two fields to make 'key' field
Hello Everybody:

I have a little problem, I would like to combine two fields; $rec{'year'}, $rec{'month'}, and assign it as the value for my key field $rec{'yearmonth'}. I would like to do this so I can do calculations on the seperate fields to compare data across records.

I have come up with something like this;

join($rec{'year'}, $rec{'month'})

or alternately;

$rec{'yearmonth'}=($rec{'year'}*100)+$rec{'month'}

- I think this would work because I can manipulate it more.

But me real problem Is where to place the code, such that it will assign it to the $rec{'key_field'}. Another twist, I cannot place this in db.cgi, because I use it for multiple databases.

Can anybody help me?

-Don
Quote Reply
Re: [don_son] Join two fields to make 'key' field In reply to
I think that you could still put it into db.cgi using an IF statement which evaluates the db name.

I find the variable $in{'db'} which you could use to control when the conditional lines are executed.

Regarding placement, if the joining is to be done when a record is added, then probably within sub add_record in db.cgi. If the new field is needed as part of a query, then sub view_records in db.cgi.

Hope that helps, sorry these are just guesses at best.

Joe
Quote Reply
Re: [joematt] Join two fields to make 'key' field In reply to
I often use:

if ($db_setup eq 'faqbrd') {
CODES
}

replacing faqbrd of course with the name of the database file you wish to use for that line or lines of code.

Unoffical DBMan FAQ
http://redundantcartridge.com/dbman/