Hi
(Select Case (select count(*) from tbl1 T where T.num = T0.num ) when 0 then
HCode=STUFF
(
(
SELECT ', '+ CAST(A0.[aCode] AS VARCHAR(MAX))
FROM O A0
INNER JOIN I A1 ON A0.[AEntry] = A1.[SEntry]
FOR XMl PATH('')
),1,1,''
) else '2' end)
from tbl5 t0
Thanks
December 15, 2021 at 11:14 am
Hi
(Select Case (select count(*) from tbl1 T where T.num = T0.num ) when 0 then HCode=STUFF ( ( SELECT ', '+ CAST(A0.[aCode] AS VARCHAR(MAX)) FROM O A0 INNER JOIN I A1 ON A0.[AEntry] = A1.[SEntry] FOR XMl PATH('') ),1,1,'' ) else '2' end)
from tbl5 t0
Thanks
What is your question?
December 15, 2021 at 11:15 am
Hi
Error is coming Invalid column HCode
Thanks
Maybe extract the constant and put the correlated subquery in the FROM clause as a CROSS APPLY
declare @vmax_var varchar(max)=
(SELECT STUFF((SELECT ', ' + CAST(A0.[aCode] AS VARCHAR(MAX))
FROM O A0
JOIN I A1 ON A0.[AEntry] = A1.[SEntry]
FOR XMl PATH('')),1,1,''));
Select HCode=case when t.t_count=0 then @vmax_var else '2' end
from tbl5 t0
cross apply (select count(*)
from tbl1 T
where T.num = T0.num) t(t_count);
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy