--------------------------------proc 1----------------------------------------create proc [dbo].[o_ustatexml]
@returnvalue xml output,
@XmlCode xml
as
declare @idoc int 
declare @mobile numeric(18,0)
declare @xmldoc xmlcreate table #table(mobile numeric(18,0))--句柄 
EXEC sp_xml_preparedocument @idoc OUTPUT, @XmlCode 
 
insert into #table(mobile)  
SELECT MO FROM OPENXML(@idoc, N'/R/I') 
WITH 

MO numeric(18,0)
)if not exists(select mobile from u_state where mobile in (select mobile from #table))
begin
set @xmldoc = '<R/>'
end
else
begin
set @xmldoc = (SELECT mobile MO,state S,[sign] SG,md5 M
FROM U_State as I
WHERE  mobile in (select mobile from #table)  FOR XML auto,ROOT('R'),Type)
end
set @returnvalue = @xmldoc--------------------------------proc 2----------------------------------------create proc [dbo].[r_ustatexml]
@XmlCode xml
AS 
BEGIN 
create table #table(mobile numeric(18,0),state int,[sign] varchar(50),md5 varchar(32))DECLARE @idoc int 
declare @mobile numeric(18,0)
declare @state int
declare @sign varchar(50) 
declare @md5 varchar(32)  
SET NOCOUNT ON;--句柄 
EXEC sp_xml_preparedocument @idoc OUTPUT, @XmlCode insert into #table(mobile,state,[sign],md5)  
SELECT MO,S,SG,M FROM OPENXML(@idoc, N'/R/I') 
WITH 

MO numeric(18,0), 
S int,
SG varchar(50),
M varchar(32)
)declare my_cursor cursor for 
select mobile,state,[sign],md5 
from #table 
Open my_cursor 
fetch next from my_cursor into @mobile,@state,@sign,@md5while @@fetch_status=0 
begin
if not exists(select mobile from U_State where mobile=@mobile)
begin
insert into U_State(mobile,state,[sign],md5) values(@mobile,@state,@sign,@md5)
end
else
begin
declare @a varchar(50)
declare @b varchar(32)
select @a = [sign],@b = md5 from #table where mobile=@mobile
if @a = '' and @b = ''
begin
update U_State set state=@state where mobile=@mobile
end
else
if @a = ''
begin
update U_State set state=@state,md5=@md5 where mobile=@mobile
end
else
if @b = ''
begin
update U_State set state=@state,[sign]=@sign where mobile=@mobile
end
else
begin
update U_State set state=@state,[sign]=@sign,md5=@md5 where mobile=@mobile
end
end
fetch next from my_cursor into @mobile,@state,@sign,@md5
end
close my_cursor 
deallocate my_cursor
update u_state set state = 0 where state = -1
drop table #table
end--------------------------------proc 3----------------------------------------create proc [dbo].[outxml]
@IMSI varchar(16),
@returnvalue varchar(max) output
as
declare @xmldoc xml
set @xmldoc = (SELECT MobileNo M,FriendName NFROM G_friend as IWHERE IMSI=@IMSI FOR XML auto,ROOT('A'),Type)
set @returnvalue = convert(varchar(max),@xmldoc)------------------------------------------------------------------------------