sql - How do I 'hardcode' a select field value when there is no join to the other table -
i have no idea if title makes sense, or if relates sql or tsql relatively new sql , come vba background, below 1 half of have (i amended it, bi package sql reader created basic select/from/where's.. , appears use rather join). if helps in understanding, use populate olap cube..so there 1 value being read , whole lot of associated field needed too.
i've managed learn bit on here (hence why i'm thinking may tsql), i'm stuck one.
i getting value *dbo.gl_acct_detail.db_amt_cc - dbo.gl_acct_detail.cr_amt_cc* , associated month (form accouting_period), org_code, acc_code , mkt_segment
mkt_segment comes prj_phase table, 'joined' acct_detail table prj_code , phase_code. problem acct_code's there no prj_code or phase_code..they null..so there can no link prj_phase table , no mkt_segment. in situation want use hardcoded/default value in place of mkt_segment value (that can't obtained). tried using case when mkt_segment in select statement didn't work.
i can in separate query (by excluding prj_phase table, , hardcoding value in select statement , putting dbo.acct_code.phase_code null)..but i'm wondering how can in 1 query.
select case when substring(cast(dbo.gl_acct_detail.accounting_period char), 5, 2) < '07' left(dbo.gl_acct_detail.accounting_period, 6) - 94 else left(dbo.gl_acct_detail.accounting_period, 6) - 6 end, dbo.gl_acct_detail.org_code, dbo.gl_acct_detail.acct_code, dbo.prj_phase.mkt_segment, case when (dbo.gl_acct_detail.fiscal_per_nbr <> '12' , dbo.gl_acct_detail.acct_code = '70199') '0' else dbo.gl_acct_detail.db_amt_cc - dbo.gl_acct_detail.cr_amt_cc end dbo.gl_acct_detail, dbo.sys_defaults, dbo.prj_phase dbo.gl_acct_detail.fiscal_year = dbo.sys_defaults.current_fiscal_year -1 , dbo.gl_acct_detail.phase_code = dbo.prj_phase.phase_code , dbo.gl_acct_detail.prj_code = dbo.prj_phase.prj_code
any help/suggestions on appreciated!!
try :
select case when substring(cast(dbo.gl_acct_detail.accounting_period char), 5, 2) < '07' left(dbo.gl_acct_detail.accounting_period, 6) - 94 else left(dbo.gl_acct_detail.accounting_period, 6) - 6 end, dbo.gl_acct_detail.org_code, dbo.gl_acct_detail.acct_code , case when (dbo.gl_acct_detail.phase_code null or dbo.gl_acct_detail.prj_code null) 'default value' else dbo.prj_phase.mkt_segment end mkt_segment, case when (dbo.gl_acct_detail.fiscal_per_nbr <> '12' , dbo.gl_acct_detail.acct_code = '70199') '0' else dbo.gl_acct_detail.db_amt_cc - dbo.gl_acct_detail.cr_amt_cc end dbo.gl_acct_detail left join dbo.sys_defaults on dbo.gl_acct_detail.fiscal_year = dbo.sys_defaults.current_fiscal_year -1 left join dbo.prj_phase on dbo.gl_acct_detail.phase_code = dbo.prj_phase.phase_code , dbo.gl_acct_detail.prj_code = dbo.prj_phase.prj_code
Comments
Post a Comment