A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Welcome to Microsoft T-SQL Q&A Forum!
Please check this:
update T1
SET T1.Result=
case when cnt=( select cnt from ##Table2 T2
where T2.Cnt=1 and T2.Code=T1.code)
then cast (T2.Price * T1.Qty as nvarchar(100))
when cnt in(select cnt from ##Table2 T2
where T2.Cnt>=2 and (T1.Amount/T1.Qty) = T2.Price)
then 'Exist' else 'NotExist' end
from ##Table1 T1 left join ##Table2 T2 on T1.Code = T2.Code
Here is result:
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.