A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Dinamic Naming in Design Grid or SQL



 
 
Thread Tools Display Modes
  #1  
Old February 22nd, 2010, 09:43 PM posted to microsoft.public.access.queries
John
external usenet poster
 
Posts: 2,649
Default Dinamic Naming in Design Grid or SQL

I have a union query that gathers financial data from a current period and a
prior period. The users uses a pick list to pick two dates. The union query
then runs the two queries and "sums" them together to get an output something
like:

current budget, prior budget, budget delta
$120 $110 $10

There are several "current-prior-delta" triplets.

My question is, in stead of naming the collumns "CBCst", "PBCst", &
"BCDelta" is there a way to name them using the format function?

Something like:

format(CurDte,"mmm-yy") & "-Budget", format(PriDgte,"mmm-yy") & "-Budget",
"BudgetDelta"

The desired result would be:

Jan-10-Budget, Dec-09-Budget, BudgetDelta

Just so I don't get chastized... Here's the Union Query:
==========
SELECT DateValue(Right(Trim([tblProjections]![period]),8)) AS CurrentPeriod,
1 As Mth, tblProjections.job, tblProjections.act, tblProjections.adesc,
tblProjections.uom, tblProjections.quan_cur, tblProjections.quan_td,
tblProjections.quan_rem, tblProjections.pc_comp, tblProjections.bdg_l_un,
tblProjections.bdg_e_un, tblProjections.bdg_m_un, tblProjections.bdg_sb_un,
tblProjections.bdg_sp_un, tblProjections.bdg_t_un, tblProjections.avgtdlun,
tblProjections.avgtdeun, tblProjections.avgtdmun, tblProjections.avgtdsbun,
tblProjections.avgtdspun, tblProjections.avgtdtun, tblProjections.ucostltc,
tblProjections.ucostetc, tblProjections.ucostmtc, tblProjections.ucostsbtc,
tblProjections.ucostsptc, tblProjections.ucostttc, tblProjections.bdg_lh_un,
tblProjections.avgtdlhun, tblProjections.ucostlhtc, tblProjections.curbdgl,
tblProjections.curbdge, tblProjections.curbdgm, tblProjections.curbdgsb,
tblProjections.curbdgsp, tblProjections.curbdgt, tblProjections.act_td_l,
tblProjections.act_td_e, tblProjections.act_td_m, tblProjections.act_td_sb,
tblProjections.act_td_sp, tblProjections.act_td_t, tblProjections.com_td_l,
tblProjections.com_td_e, tblProjections.com_td_m, tblProjections.com_td_sb,
tblProjections.com_td_sp, tblProjections.com_td_t, tblProjections.frcsttcl,
tblProjections.frcsttce, tblProjections.frcsttcm, tblProjections.frcsttcsb,
tblProjections.frcsttcsp, tblProjections.frcsttct, tblProjections.sl_prj_l,
tblProjections.sl_prj_e, tblProjections.sl_prj_m, tblProjections.sl_prj_sb,
tblProjections.sl_prj_sp, tblProjections.sl_prj_t, tblProjections.pcstmanl,
tblProjections.pcstmane, tblProjections.pcstmanm, tblProjections.pcstmansb,
tblProjections.pcstmansp, tblProjections.pcstmant, tblProjections.commflag,
tblProjections.var_l, tblProjections.var_e, tblProjections.var_m,
tblProjections.var_sb, tblProjections.var_sp, tblProjections.var_t,
tblProjections.manchgl, tblProjections.manchge, tblProjections.manchgm,
tblProjections.manchgsb, tblProjections.manchgsp, tblProjections.manchgt,
tblProjections.hrcurbudg, tblProjections.hractltd, tblProjections.hrfrcsttc,
tblProjections.hrslproj, tblProjections.hrprjwman, tblProjections.hrvar,
tblProjections.hrmanchg, tblProjections.ahrcurbdg, tblProjections.ahractltd,
tblProjections.ahrfcsttc, tblProjections.ahrslproj, tblProjections.ahrpjwman,
tblProjections.rpf, tblProjections.l, tblProjections.e, tblProjections.m,
tblProjections.sb, tblProjections.sp, tblProjections.flag,
tblProjections.audit, tblProjections.pr_key, tblProjections.sd_key
FROM tblProjections
WHERE
(((DateValue(Right(Trim([tblProjections]![period]),8)))=[forms]![frmProjectCost]![CmbCurPro]))
ORDER BY tblProjections.act, 1

UNION ALL SELECT DateValue(Right(Trim([tblProjections]![period]),8)) AS
PriorPeriod, 2 As Mth, tblProjections.job, tblProjections.act,
tblProjections.adesc, tblProjections.uom, tblProjections.quan_cur,
tblProjections.quan_td, tblProjections.quan_rem, tblProjections.pc_comp,
tblProjections.bdg_l_un, tblProjections.bdg_e_un, tblProjections.bdg_m_un,
tblProjections.bdg_sb_un, tblProjections.bdg_sp_un, tblProjections.bdg_t_un,
tblProjections.avgtdlun, tblProjections.avgtdeun, tblProjections.avgtdmun,
tblProjections.avgtdsbun, tblProjections.avgtdspun, tblProjections.avgtdtun,
tblProjections.ucostltc, tblProjections.ucostetc, tblProjections.ucostmtc,
tblProjections.ucostsbtc, tblProjections.ucostsptc, tblProjections.ucostttc,
tblProjections.bdg_lh_un, tblProjections.avgtdlhun, tblProjections.ucostlhtc,
tblProjections.curbdgl, tblProjections.curbdge, tblProjections.curbdgm,
tblProjections.curbdgsb, tblProjections.curbdgsp, tblProjections.curbdgt,
tblProjections.act_td_l, tblProjections.act_td_e, tblProjections.act_td_m,
tblProjections.act_td_sb, tblProjections.act_td_sp, tblProjections.act_td_t,
tblProjections.com_td_l, tblProjections.com_td_e, tblProjections.com_td_m,
tblProjections.com_td_sb, tblProjections.com_td_sp, tblProjections.com_td_t,
tblProjections.frcsttcl, tblProjections.frcsttce, tblProjections.frcsttcm,
tblProjections.frcsttcsb, tblProjections.frcsttcsp, tblProjections.frcsttct,
tblProjections.sl_prj_l, tblProjections.sl_prj_e, tblProjections.sl_prj_m,
tblProjections.sl_prj_sb, tblProjections.sl_prj_sp, tblProjections.sl_prj_t,
tblProjections.pcstmanl, tblProjections.pcstmane, tblProjections.pcstmanm,
tblProjections.pcstmansb, tblProjections.pcstmansp, tblProjections.pcstmant,
tblProjections.commflag, tblProjections.var_l, tblProjections.var_e,
tblProjections.var_m, tblProjections.var_sb, tblProjections.var_sp,
tblProjections.var_t, tblProjections.manchgl, tblProjections.manchge,
tblProjections.manchgm, tblProjections.manchgsb, tblProjections.manchgsp,
tblProjections.manchgt, tblProjections.hrcurbudg, tblProjections.hractltd,
tblProjections.hrfrcsttc, tblProjections.hrslproj, tblProjections.hrprjwman,
tblProjections.hrvar, tblProjections.hrmanchg, tblProjections.ahrcurbdg,
tblProjections.ahractltd, tblProjections.ahrfcsttc, tblProjections.ahrslproj,
tblProjections.ahrpjwman, tblProjections.rpf, tblProjections.l,
tblProjections.e, tblProjections.m, tblProjections.sb, tblProjections.sp,
tblProjections.flag, tblProjections.audit, tblProjections.pr_key,
tblProjections.sd_key
FROM tblProjections
WHERE
(((DateValue(Right(Trim([tblProjections]![period]),8)))=[forms]![frmProjectCost]![CmbPriPro]))
ORDER BY tblProjections.act, 2;
==========

This query is used in another query to sum by the Mth (1 or 2) to get the
two values to calculate the difference.

--
Thanks in advance!
**John**
  #2  
Old March 1st, 2010, 07:59 AM posted to microsoft.public.access.queries
PieterLinden via AccessMonster.com
external usenet poster
 
Posts: 307
Default Dinamic Naming in Design Grid or SQL

John wrote:
I have a union query that gathers financial data from a current period and a
prior period. The users uses a pick list to pick two dates. The union query
then runs the two queries and "sums" them together to get an output something
like:

current budget, prior budget, budget delta
$120 $110 $10

There are several "current-prior-delta" triplets.

My question is, in stead of naming the collumns "CBCst", "PBCst", &
"BCDelta" is there a way to name them using the format function?


In a word, no. The only way to rename a column is to use AS...

SELECT CBCst AS 'Current Budget', PBCst AS 'Prior Budget', BCDelta AS 'Budget
Delta'
FROM....

if you to this in the first select statement in your union query, you'll get
the naming okay. As for doing this on the fly - no can do... Only way to do
that is to modify the QueryDef's SQL property (basically using VBA under the
covers.)

--
Message posted via http://www.accessmonster.com

  #3  
Old March 1st, 2010, 02:06 PM posted to microsoft.public.access.queries
John
external usenet poster
 
Posts: 2,649
Default Dinamic Naming in Design Grid or SQL

Thanks for the feedback... I was afraid that would be the answer...
--
Thanks in advance!
**John**


"PieterLinden via AccessMonster.com" wrote:

John wrote:
I have a union query that gathers financial data from a current period and a
prior period. The users uses a pick list to pick two dates. The union query
then runs the two queries and "sums" them together to get an output something
like:

current budget, prior budget, budget delta
$120 $110 $10

There are several "current-prior-delta" triplets.

My question is, in stead of naming the collumns "CBCst", "PBCst", &
"BCDelta" is there a way to name them using the format function?


In a word, no. The only way to rename a column is to use AS...

SELECT CBCst AS 'Current Budget', PBCst AS 'Prior Budget', BCDelta AS 'Budget
Delta'
FROM....

if you to this in the first select statement in your union query, you'll get
the naming okay. As for doing this on the fly - no can do... Only way to do
that is to modify the QueryDef's SQL property (basically using VBA under the
covers.)

--
Message posted via http://www.accessmonster.com

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:00 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.