Hello,
I have a table A
I have to create a way where we can compare records to table B and if records match then we should give a flag in table A to corresponding loan as 'Y' or 'N'
Can we do this in sp?
Thanks
Thanks Cris...So each time we execute sp we have to provide parameter for id...Is there any way an sp checks all the records in Table A and Table B at same time?
Thanks
You don't need a SP, you probably can do it using a SQL like following:
update A set A.loan = C.loan
from
( select distinct A.id as id,
A.atr1 as atr1, A.atr2 as atr2,
case when B.id is null then 'No'
else 'Yes' end as loan
from A left outer join B
on A.id = B.id and A.atr1 = B.atr1b
and A.atr2=B.atr2b) C
where A.id = C.id and A.atr1 = C.atr1
and A.atr2=C.atr2
You don't need a SP, you probably can do it using a SQL like following:
update A set A.loan = C.loan
from
( select distinct A.id as id,
A.atr1 as atr1, A.atr2 as atr2,
case when B.id is null then 'No'
else 'Yes' end as loan
from A left outer join B
on A.id = B.id and A.atr1 = B.atr1b
and A.atr2=B.atr2b) C
where A.id = C.id and A.atr1 = C.atr1
and A.atr2=C.atr2
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.