September 10, 2007 at 4:27 pm
I am trying something like code below... I am getting @TableName from a separate table and need to determine if I am updating or inserting a new record into the given @TableName. The line giving me problems is IF (EXEC(@Query)) -- It almost seems like I need to setup a temporary table, insert the exec rows into that table (if any) and then use that as my conditional statement, but that seems like a lot of overhead.. hopefully there is a more elegant solutions. Thanks for any pointers.
SET @Query = 'SELECT id FROM ' + @TableName + ' WHERE id = ' + @id
IF (EXEC (@Query))
BEGIN
SET @Query = 'UPDATE ' + @TableName + ' ...
EXEC (@Query)
END
ELSE
BEGIN
SET @Query = 'INSERT INTO ' + @TableName + ' ...
EXEC (@Query)
END
September 10, 2007 at 4:37 pm
It looks (from the example provided) you just want to do an upsert. I would recommend that if that's what you're trying to do, using the method described here:
http://209.34.241.68/mat_stephen/archive/2005/08/31/410022.aspx
September 11, 2007 at 8:40 am
I'm not sure if that will work.. The source results has a field that assigns the @TableName and @FieldName .. ultimately I have an "Answer" field in the source results that is mapped to @TableName.@FieldName on a per-record basis. As a result, I am not sure what the "Destination" would be in the provided link..
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply