• I copied the script off of the page, and pasted it into a Notepad++ buffer to look at it. One thing that was kind of odd were the strange characters, which Notepad++ represented by a several "?" characters, which I assume was Notepad++ trying to give me something that went beyond the normal ANSI characterset. All I did was replace each of those "?" with a blank, and that seems to have worked. I ran the script which created the GenerateInsUpdateScript stored procedure.

    In looking at your code I see that your write everything that would generate the CREATE PROCEDURE script into a temporary table and then perform a SELECT against that. However, one thing that I also noticed was that the script that GenerateInsUpdateScript generates isn't quite a complete stored proc. It is missing the BEGIN and END statements for a SP. And also I noticed that between the declaration of the SP and its parameters there is a NULL, as well as there is a NULL between the INSERT statement and the UPDATE statement that GenerateInsUpdateScript comes up with. Still, this is great, because I would hate to do all that GenerateInsUpdateScript does for me! I was thinking that I could just go to the NULL statements and replace them with logic. Something like:

    IF (SELECT COUNT(*) FROM myTable WHERE LastName = @LastName) = 0

    BEGIN

    --Do the INSERT statement

    END

    ELSE

    BEGIN

    --Do the UPDATE statement

    END

    Does that make sense to you?

    Kindest Regards, Rod Connect with me on LinkedIn.