SQL XML DELETE
--A. 从存储在非类型化的 xml 变量中的文档中删除节点
DECLARE @myDoc xml
SET @myDoc = '<?Instructions for=TheWC.exe ?>
<Root>
<!-- instructions for the 1st work center -->
<Location LocationID="10" LaborHours="1.1" MachineHours=".2" >
Some text 1
<step>Manufacturing step 1 at this work center</step>
<step>Manufacturing step 2 at this work center</step>
</Location>
</Root>'
SELECT @myDoc
-- delete an attribute
SET @myDoc.modify('
delete /Root/Location/@MachineHours
')
SELECT @myDoc
-- delete an element
SET @myDoc.modify('
delete /Root/Location/step[2]
')
SELECT @myDoc
-- delete text node (in <Location>
SET @myDoc.modify('
delete /Root/Location/text()
')
SELECT @myDoc
-- delete all processing instructions
SET @myDoc.modify('
delete //processing-instruction()
')
SELECT @myDoc
--B. 从存储在非类型化的 xml 列中的文档中删除节点
delete XML DML 语句从存储在列中的文档中删除 <Features> 的第二个子元素。
CREATE TABLE #T (i int, x xml)
go
INSERT INTO #T VALUES(1,'<Root>
<ProductDescription ProductID="1" ProductName="Road Bike">
<Features>
<Warranty>1 year parts and labor</Warranty>
<Maintenance>3 year parts and labor extended maintenance is available</Maintenance>
</Features>
</ProductDescription>
</Root>')
go
-- verify the contents before delete,query返回Features元素下的所有节点,以XML格式返回
SELECT x.query('//ProductDescription/Features')
from #T
-- delete the second feature
UPDATE #T
SET x.modify('delete /Root/ProductDescription/Features/*[2]')
-- verify the deletion
SELECT x.query(' //ProductDescription/Features')
from #T
DROP TABLE #T
C. 从非类型化的 xml 列中删除节点
create table #T(ProductModelID int primary key,
Instructions xml )
go
insert #T
select ProductModelID, Instructions
from Prod
相关文档:
创建XML文件:
public boolean createXML(){
try{
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("root");
Element personNode = root.addElement("person");
Element sonNode = personNode ......
Select CONVERT(varchar(100), GETDATE(), 0) as 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1) as 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2) as 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3) as 16/05/06
Select CONVERT(varchar(100), GETDATE(), 4) as 16.05.06
Select CON ......
摘自:http://www.cnblogs.com/dicky/archive/2007/01/12/618453.html
格式:
CONVERT(data_type,expression[,style])
说明:
此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,char,varchar)
相互转换的时候才用到.
例子:
SELECT CONVERT(varchar(30),getdate(),101) now
结果为 ......
TA:
1,WANG
2,ZHANG
4,LI
TB:
1,100
2,200
3,400
1.left join 左连接--以左表为基准,右表中没值的,在结果集中以null值代替。(select * from TA left join TB where TA.ID=TB.ID)
1,WANG,100
2,ZHANG,200
4,NULL
2.right join 右连接--以右表为基准,左表中没值的,在 ......