sonofstimpy1
asked on
Dynamic SQL
I'm looking to change a call date from a static subquery like..
to Dynamic SQL so that it pulls dates between the first and last day of the previous month.
Can anyone give me an idea to do this?
where a.CALL_DATE between '12/1/2012' and '12/31/2012'
to Dynamic SQL so that it pulls dates between the first and last day of the previous month.
Can anyone give me an idea to do this?
ASKER
How would I fit this into this example of code I already have?
Noting line 5 is the part I need to make dynamic...
Noting line 5 is the part I need to make dynamic...
select c.TAX_ID as "TAXID", date( rtrim( char(year (current_date - 1 month)))||'-'||rtrim(char(month (current_date - 1 month)))||'-01') as "RUN_DT", 320 as "TYP", Count(*) as "cnt"
from
(select a.SERVER_CD, a.PORT_NUMBER, a.CALL_DATE, a.CALL_START_TIME, b.TAX_ID, b.MODULE_NAME
from hum.a_vrhcal a, hum.a_vrhact b
where a.CALL_DATE between '12/1/2012' and '12/31/2012'
and a.CALLER_TYPE_IND = 'P'
and not a.server_cd like 'D%'
and not a.server_cd = 'PR'
and not b.MODULE_NAME = 'GREETING'
and not b.MODULE_NAME like '%ELIGIBILITY%'
and not b.MODULE_NAME like '%CLAIM%'
and not b.MODULE_NAME like '%PRECERTIFICATION%'
and not b.MODULE_NAME like '%REFERRALS%'
and not b.MODULE_NAME IN ('MAIN MENU','AALTDRUGLST','AAPID','ACOMEM','ACONFDOB','ACONFDRUGNAME','ACONFMID','ACPID','ADOBP','ADOBPT','ADRUGNAME','AENDM','AFAXYESNO','AGETDOSAGE','AGETFAX','AHEARAGAIN','ALTDRUGTRANS','AMID','ANEEDSMET','ANEWREQHWSE','ASPECNOMID','ASTATORREQ','AVERFAX','DRUGDETAILTRANS','DrugPricing_Reason','DRUGPRICINGREASON','DRUGPRICINGTRANS','EESDEDUCT','EESFAMILY','FAXFORMAVAILTRANS','FAXSENDTRANS','LISTDRUGREPLY','RXArgusElig','VRAUTH','VRDAUTH','VRMAUTH','VRPAUTH')
and not a.DNIS = 3055
and a.SERVER_CD = b.SERVER_CD
and a.PORT_NUMBER = b.PORT_NUMBER
and a.CALL_DATE = b.CALL_DATE
and a.CALL_START_TIME = b.CALL_START_TIME
group by a.SERVER_CD, a.PORT_NUMBER, a.CALL_DATE, a.CALL_START_TIME, b.TAX_ID, b.MODULE_NAME) as c
group by TAX_ID, date( rtrim( char(year (current_date - 1 month)))||'-'||rtrim(char(month (current_date - 1 month)))||'-01'), MODULE_NAME;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great work sjwales!
Open in new window
If you have time as well, use @end2 (which is the first of this month) and instead of between construct a where clause that's
>= @start and < @end2