我希望在检查后存在或在表中不存在时插入表中。 如果不存在插入,如果不存在则插入。
INSERT INTO Database.[dbo].[TBL_AllProduct]
([Product_Name]
,[Product_URL])
SELECT
t.v.value('(span[2]/a/text())[1]','nvarchar(max)') as [Name],
t.v.value('(span[2]/a/@href)[1]','nvarchar(max)') as [URL]
FROM @html.nodes('div/div') as t(v)
[name]
@html.nodes
value
[name]
column
{}} [product_name]
{}} {}从@html.nodes
t(v)
包含任何行,不仅包含1行。
exmaple for export t(v)
--------------
NAME
--------------
piter
alex
sony
telephon
.
.
.
答案 0 :(得分:1)
DECLARE @Name Nvarchar(50)
SET @Name=t.v.value('(span[2]/a/text())[1]','nvarchar(max)') as [Name] FROM @html.nodes('div/div') as t(v)
IF NOT EXISTS (SELECT Product_Name FROM Database.[dbo].[TBL_AllProduct] WHERE Product_Name=@Name) BEGIN
INSERT INTO Database.[dbo].[TBL_AllProduct]
([Product_Name]
,[Product_URL])
SELECT
t.v.value('(span[2]/a/text())[1]','nvarchar(max)') as [Name],
t.v.value('(span[2]/a/@href)[1]','nvarchar(max)') as [URL]
FROM @html.nodes('div/div') as t(v)
END