Tupacmoche
Registered User.
- Local time
- Today, 12:57
- Joined
- Apr 28, 2008
- Messages
- 291
Hi SQL Masters,
I have a block of code that work perfectly but need to run it against dozens of tables. It does not make any sense to repeat it. What structure can, I use to run this code and loop through many different tables? See code below. Besides the table name changing, the tbl_id in the case statement will also change.
Select SourcePatientMRN
,SourceIs =(Case When e.Match = 'Y' then 1 else 0 end)
, TargetIs =(Case When n.Match = 'Y' then 1 else 0 end)
, tbl_id =(Case when e.Match = 'Y' then 'EN' else 'EN' end)
from MRN_Processing as m
Left join
(Select *, 'Y' as Match
from tmpEpic_Name
) as e on e.MRN = m.SourcePatientMRN
Left join
( Select *, 'Y' as Match
from tmpEpic_Name
) as n on n.MRN = m.TargetPatientMRN
I have a block of code that work perfectly but need to run it against dozens of tables. It does not make any sense to repeat it. What structure can, I use to run this code and loop through many different tables? See code below. Besides the table name changing, the tbl_id in the case statement will also change.
Select SourcePatientMRN
,SourceIs =(Case When e.Match = 'Y' then 1 else 0 end)
, TargetIs =(Case When n.Match = 'Y' then 1 else 0 end)
, tbl_id =(Case when e.Match = 'Y' then 'EN' else 'EN' end)
from MRN_Processing as m
Left join
(Select *, 'Y' as Match
from tmpEpic_Name
) as e on e.MRN = m.SourcePatientMRN
Left join
( Select *, 'Y' as Match
from tmpEpic_Name
) as n on n.MRN = m.TargetPatientMRN