我有一张桌子
CREATE TABLE #tmp
(
ProcedureID INT ,
ProcedureName NVARCHAR(100) ,
OriginalVariableName NVARCHAR(200) ,
StatementNumber INT ,
RuleStatementID INT ,
StatementXML NVARCHAR(MAX) ,
CountOrg INT DEFAULT 0 ,
[Count] INT DEFAULT 0 ,
VarID INT ,
ParentID INT ,
ParentName NVARCHAR(100) ,
StatementType NVARCHAR(20) ,
[Type] NVARCHAR(3) ,
xml XML ,
str NVARCHAR(MAX) ,
Opindex INT ,
)
我从另一个表中获取日期并插入上表
在StatementXML列中,xml值与以下相同
CUSTOMER-MASTER- RECORDXYZABCaabb
我想找到标签aa和bb的值,它可能是空白或某些值
如果我在两个标签中都找到了值,那么我想更新#tmp table
的Type列我想从标签和标签中找到值
喜欢 -
ID,列,值
1,,
2,XYZ,aa
3,ABC,bb
....
....
....
以表格格式
我怎么能在商店程序中这样做。
请在这里帮忙。 根据生成值,我想更新其他表中的某些值。
我也检查下面的方法,但我得不到值
declare @x xml = '<INSERT STATEMENTNUMBER="1595" CURSORNAME="" FILENAME="" INPUTTYPE="" RESPCODE=""><INSERTSTATEMENT>
<TABLES><TABLE><NAME>VIDEO-MASTER-RECORD</NAME><ALIAS></ALIAS></TABLE>
</TABLES><JOINS><JOIN><TYPE></TYPE><TABLE><NAME></NAME><ALIAS></ALIAS></TABLE></JOIN></JOINS>
<COLUMNS><COLUMN><NAME>VM-VIDEO-NUMBER</NAME></COLUMN><COLUMN><NAME>VM-TITLE</NAME></COLUMN><COLUMN><NAME>VM-MEDIA-TYPE</NAME>
</COLUMN><COLUMN><NAME>VM-STATUS</NAME></COLUMN><COLUMN><NAME>VM-CUSTOMER-NUMBER</NAME></COLUMN><COLUMN><NAME>VM-DATE-OUT</NAME></COLUMN></COLUMNS>
<VALUES>VIDEO-MASTER-RECORD</VALUES></INSERTSTATEMENT></INSERT>'
select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER,
@x.value('(//COLUMN/NAME)[1]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[1]', 'varchar(max)') AS 'value1' INTO aa
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[2]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[2]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[3]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[3]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[4]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[4]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[5]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[5]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[6]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[6]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[7]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[7]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[8]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[8]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[9]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[9]', 'varchar(max)') AS 'value1'
Insert into aa select @x.value('(/INSERT/@STATEMENTNUMBER)[1]', 'int') as STATEMENTNUMBER, @x.value('(//COLUMN/NAME)[10]', 'varchar(max)') AS 'column1' ,@x.value('(//VALUES)[10]', 'varchar(max)') AS 'value1'
我的结果是aa表
STATEMENTNUMBER column1 value1
1595 VM-TITLE NULL
1595 VM-MEDIA-TYPE NULL
1595 VM-STATUS NULL
1595 VM-CUSTOMER-NUMBER NULL
1595 VM-DATE-OUT NULL
1595 NULL NULL
1595 NULL NULL
1595 NULL NULL
1595 NULL NULL
1595 VM-VIDEO-NUMBER VIDEO-MASTER-RECORD
所以我需要根据最后一行更新值,因为两列都有值VM-VIDEO-NUMBER和VIDEO-MASTER-RECORD,我想忽略或删除column1或value1具有空值的行 请建议