June 28, 2010 at 1:48 am
Hello,
I want to insert the record in to a table using bulk insert method fro that I use the below
EXEC sp_xml_preparedocument @index OUTPUT, @xmlReviewComments
INSERT INTO PC_Tbl_FooterTemplate_Position
(
TemplateId,
Position,
[Content]
)
SELECT @FooterId ,Position,Content
FROM OPENXML (@index, '/NewDataSet/Table1')
WITH (
Templateid bigint 'Templateid',
Position nvarchar(50) 'Position',
Content nvarchar(500) 'Content'
)
EXEC sp_xml_removedocument @index
above is an Example
Before insert How can I check for a duplication whether the insertion record already present in the table.
I don't want to insert duplicate records to table.
Please help me to avoid duplicate insert while bulk upload.
Thanks
Regards,
Mohanaraj.S
June 28, 2010 at 6:35 am
Try this:
INSERT INTO PC_Tbl_FooterTemplate_Position
(
TemplateId,
Position,
[Content]
)
SELECT @FooterId, Position, Content
FROM OPENXML (@index, '/NewDataSet/Table1')
WITH (
Templateid bigint 'Templateid',
Position nvarchar(50) 'Position',
Content nvarchar(500) 'Content'
) indx
LEFT JOIN PC_Tbl_FooterTemplate_Position pp
ON pp.TemplateId = indx.Templateid
-- ? what are the keys of PC_Tbl_FooterTemplate_Position table?
-- add them all into join here! (don't need to change where clause, it is enough to check one key column for null)
WHERE pp.TemplateId IS NULL
June 28, 2010 at 7:21 am
mohanaraj (6/28/2010)
...I want to insert the record in to a table using bulk insert method fro that I use the below...
It's good practice to use a staging table when importing data. Specify column types to maximise data capture. Run TSQL validation / dedupe scripts against it. Flag up rows for eyeball validation.
Everything in your database is valuable, everything outside is garbage. A staging table serves as a firewall between the two.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
June 28, 2010 at 4:19 pm
Chris Morris-439714 (6/28/2010)
Everything in your database is valuable, everything outside is garbage. A staging table serves as a firewall between the two.
VERY well stated, Mr Morris! ๐
--Jeff Moden
Change is inevitable... Change for the better is not.
July 2, 2010 at 3:27 am
Jeff Moden (6/28/2010)
Chris Morris-439714 (6/28/2010)
Everything in your database is valuable, everything outside is garbage. A staging table serves as a firewall between the two.VERY well stated, Mr Morris! ๐
Thanks Jeff! It never ceases to amaze me how resistant some folks can be to something so obvious.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply