Renamingtables from a CASE

  • Hello :),

    Need some help whid renaming the differente tables that this CASE can give this is part of a SP

    can any one help out plz

    Thanks

    ''CASE

    WHEN '+@ID_Tipo+' = ''0''

    THEN (SELECT d.Designacao FROM [Departamento] AS d

    WHERE 0 = '+@ID_Categoria+')

    WHEN '+@ID_Tipo+' >= 1

    THEN (SELECT c.Designacao FROM [Cargo] as c

    WHERE '+@ID_Categoria+'>=1)

    END ,''

  • Why have you decided on using dynamic SQL?

    Please, post table DDL, sample data and expected results.

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • Your partial query doesn't make sense to me. It looks like you're building a Case statement inside a dynamic SQL string, and in the Case statement, you've got table selects with table aliases. I could be mistaken, but I don't think Case is going to do what you seem to be trying to accomplish here.

    What is the end-result you're trying for?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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