• lmeinke (11/13/2013)


    Correction....those errors were due to my sloppy typing....but back to the original error:

    Msg 240, Level 16, State 1, Line 1

    Types don't match between the anchor and the recursive part in column "STD SKU" of recursive query "rCTE".

    In my original post, the rCTE started like this:

    WITH rCTE AS

    (

    SELECT n=0, ITEM

    ,rn=ROW_NUMBER() OVER (ORDER BY (SELECT NULL))

    ,ITEM1=ITEM

    ,ITEM2=NULL

    FROM

    In my suggested correction for this error, it looks like this.

    WITH rCTE AS

    (

    SELECT n=0, ITEM

    ,rn=ROW_NUMBER() OVER (ORDER BY (SELECT NULL))

    ,ITEM1=ITEM

    ,ITEM2=CAST(NULL AS VARCHAR(20))

    FROM

    So did you remember to add the CAST around the NULL for ITEM2? The length of the VARCHAR should match whatever the length of your product code is in the table.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St