EDIT: In case this doesn't make it into the actual article, I wanted to clarify a few items.
1. The script has a few restricting conditions that you may want to remove. Specifically, the check for “IsActive” or “Active” columns.
2. The output, if copied and pasted into a new window should retain the proper formatting.
3. Your table MUST have a Primary Key defined.
4. Replacing the final select (that returns the statement) with the below code will handle >, < and & conversions caused by the use of XML datatype.
BEGIN
SELECT
REPLACE(REPLACE(REPLACE(REPLACE(@sqlTextFirst +
STUFF((SELECT
UsingList AS [text()]
FROM
#DataToMerge
FOR XML PATH(''))
,1,1,'')+
@sqlTextSecond
,'USING (VALUES ,(','USING (VALUES ('), '<', '<'), '>', '>'), '&', '&')
END
** The USING clause should look like this.
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. Selburg