Incorrect Syntax near cast expected as

  • Hi

    select T0.num,T0.doc,T0.CCode,
    (stuff((select cast(', ' + convert(varchar(max),A0.doc)) as 'No' from od A0 inner join dl A1
    on A0.Doc = A1.Doc where (A0.Base = T0.doc) for xml path ('')),1,2,'')) as 'No.'
    from or T0
    inner join oc t1 on T0.Code = t1.Code

    Thanks

  • from or T0 OR is a reserved keyword, if your table is really called or then you need to delimit identify it (or better yet, rename it to something that isn't a reserved keyword).

    Also you have cast(', ' + convert(varchar(max),A0.doc)) but you don't define what you are CASTing the expression to. The syntax is CAST({expression} AS {datatype})

    Also, use meaningful aliases, T0, A0, etc, aren't helpful aliases. Bertrand wrote an article on why these are poor choices: Bad Habits to Kick : Using table aliases like (a, b, c) or (t1, t2, t3)

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply