CTE Help

  • Hi all,

    Will the CTE executes a Dynamic SQl.

    Please help me for the following.

    For Ex:

    With Cte as

    (

    Set @CntSQL = 'SELECT * FROM (SELECT A.Companyid,A.Category

    FROM ' + @Name + '.DBO.TABLE A join ' + @@Name + '.dbo.TAble B

    On A.Category = B.CategoryUsed) o PIVOT

    (COUNT(Category) FOR Category IN (


    ,[HT],[SAFETY],[SKILLS],[OTHER])) p'

    Exec (@CntSQL)

    )

    Thanks,

    Nithyapriya


    Kindest Regards,

    R

  • The real question is "Why do you think you need a CTE for this?".

    See http://www.sommarskog.se/dynamic_sql.html before you enter the land of denormalization.

     

     


    N 56°04'39.16"
    E 12°55'05.25"

  • BOL says that select expression in CTE has to meet same requirements as the one for view, so no dynamic SQL inside.

    ...and your only reply is slàinte mhath

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

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