Invalid column Name Hcode

  • 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

  • jagjitsingh wrote:

    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?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Hi

    Error is coming  Invalid column HCode

    Thanks

  • jagjitsingh wrote:

    Hi

    Error is coming  Invalid column HCode

    Thanks

    Still no question.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • 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