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?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Hi

    Error is coming  Invalid column HCode

    Thanks

  • jagjitsingh wrote:

    Hi

    Error is coming  Invalid column HCode

    Thanks

    Still no question.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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