• I found another bug with an easy win:

    Columns that include spaces need to be enclosed in square brackets.

    DECLARE @ALLcolumns TABLE (idcol1 INT IDENTITY,colname VARCHAR(100))

    INSERT INTO @ALLcolumns (colname)SELECT '[' + columnName + ']' FROM @pkInfo

    DECLARE @cnt INT

    DECLARE @clncnt INT

    SELECT @cnt=1

    SELECT @clncnt=COUNT(*) FROM @ALLcolumns

    DECLARE @cols VARCHAR(400)

    SELECT @cols=''

    while @clncnt>=@cnt

    begin

    select @cols=@cols+','+ colname FROM @ALLcolumns WHERE idcol1=@cnt

    select @cnt=@cnt+1

    end

    select @columns=SUBSTRING(@cols,2,len(@cols))

    Excellent script that solved my problem exactly as required. It would be nice if Microsoft would include a TRUNCATE PARTITION function, but this does the job for now. Thanks.