here is my query, when i run it the second time , it says #tmp1 is there already and i get an error. is there a way to drop the table after the report is run .
SELECT CS_ID, PGM_TYP_CD, MAX(UPD_DTM) AS selectedUPD_DTM
INTO #TMP1
FROM cis.dbo.CS_PGM
WHERE (EFF_END_DT IS NULL)
GROUP BY CS_ID, PGM_TYP_CD
select *
from cis.dbo.cs_pgm pgm
inner join cis.dbo.se_csld csld
on pgm.csld_id = csld.csld_id
inner join cis.dbo.bi_dtl bi
on pgm.cs_id = bi.cs_id and pgm.pgm_typ_cd = bi.pgm_typ_cd
inner join cis.dbo.rt_pick_locn locn
on bi.iss_site_cd = locn.pick_locn_cd
inner join cis.dbo.#TMP1
on pgm.cs_id = #TMP1.cs_id and
pgm.pgm_typ_cd = #TMP1.pgm_typ_cd and
pgm.upd_dtm = #TMP1.selectedUPD_DTM
where
PGM.PGM_TYP_CD = 'GA' and
PGM.EFF_END_DT is null and
--{BI.BEN_BGN_DT} = {?Benefit Begin Date} and
LOCN.EFF_END_DT is null and
BI.USE_AMT > 0 and
LOCN.PICK_LOCN_TYP = 'V'
SELECT CS_ID, PGM_TYP_CD, MAX(UPD_DTM) AS selectedUPD_DTM
INTO #TMP1
FROM cis.dbo.CS_PGM
WHERE (EFF_END_DT IS NULL)
GROUP BY CS_ID, PGM_TYP_CD
select *
from cis.dbo.cs_pgm pgm
inner join cis.dbo.se_csld csld
on pgm.csld_id = csld.csld_id
inner join cis.dbo.bi_dtl bi
on pgm.cs_id = bi.cs_id and pgm.pgm_typ_cd = bi.pgm_typ_cd
inner join cis.dbo.rt_pick_locn locn
on bi.iss_site_cd = locn.pick_locn_cd
inner join cis.dbo.#TMP1
on pgm.cs_id = #TMP1.cs_id and
pgm.pgm_typ_cd = #TMP1.pgm_typ_cd and
pgm.upd_dtm = #TMP1.selectedUPD_DTM
where
PGM.PGM_TYP_CD = 'GA' and
PGM.EFF_END_DT is null and
--{BI.BEN_BGN_DT} = {?benefit_beg_date} and
LOCN.EFF_END_DT is null and
BI.USE_AMT > 0 and
LOCN.PICK_LOCN_TYP = 'V'
SELECT CS_ID, PGM_TYP_CD, MAX(UPD_DTM) AS selectedUPD_DTM
INTO #TMP1
FROM cis.dbo.CS_PGM
WHERE (EFF_END_DT IS NULL)
GROUP BY CS_ID, PGM_TYP_CD
select *
from cis.dbo.cs_pgm pgm
inner join cis.dbo.se_csld csld
on pgm.csld_id = csld.csld_id
inner join cis.dbo.bi_dtl bi
on pgm.cs_id = bi.cs_id and pgm.pgm_typ_cd = bi.pgm_typ_cd
inner join cis.dbo.rt_pick_locn locn
on bi.iss_site_cd = locn.pick_locn_cd
inner join cis.dbo.#TMP1
on pgm.cs_id = #TMP1.cs_id and
pgm.pgm_typ_cd = #TMP1.pgm_typ_cd and
pgm.upd_dtm = #TMP1.selectedUPD_DTM
where
PGM.PGM_TYP_CD = 'GA' and
PGM.EFF_END_DT is null and
--{BI.BEN_BGN_DT} = {?Benefit Begin Date} and
LOCN.EFF_END_DT is null and
BI.USE_AMT > 0 and
LOCN.PICK_LOCN_TYP = 'V'
SELECT CS_ID, PGM_TYP_CD, MAX(UPD_DTM) AS selectedUPD_DTM
INTO #TMP1
FROM cis.dbo.CS_PGM
WHERE (EFF_END_DT IS NULL)
GROUP BY CS_ID, PGM_TYP_CD
select *
from cis.dbo.cs_pgm pgm
inner join cis.dbo.se_csld csld
on pgm.csld_id = csld.csld_id
inner join cis.dbo.bi_dtl bi
on pgm.cs_id = bi.cs_id and pgm.pgm_typ_cd = bi.pgm_typ_cd
inner join cis.dbo.rt_pick_locn locn
on bi.iss_site_cd = locn.pick_locn_cd
inner join cis.dbo.#TMP1
on pgm.cs_id = #TMP1.cs_id and
pgm.pgm_typ_cd = #TMP1.pgm_typ_cd and
pgm.upd_dtm = #TMP1.selectedUPD_DTM
where
PGM.PGM_TYP_CD = 'GA' and
PGM.EFF_END_DT is null and
--{BI.BEN_BGN_DT} = {?benefit_beg_date} and
LOCN.EFF_END_DT is null and
BI.USE_AMT > 0 and
LOCN.PICK_LOCN_TYP = 'V'