日期:2014-05-17 浏览次数:20536 次
--测试XML备份
if object_id('Proc_Insert_TestXmlInfo','P') is not null
drop procedure Proc_Insert_TestXmlInfo;
go
create proc Proc_Insert_TestXmlInfo
@ModelName nvarchar(20),
@BarcodeNo nvarchar(20),
@Station nvarchar(5),
@XmlInfo varchar(4096),
@Ret int output
as
set nocount on;
begin
declare @tb_name nvarchar(20),@SerID int
set @Ret=-1
-- 设置数据表名
if(Month(getdate()) > 6)
begin
set @tb_name = 'Y' + Convert(nvarchar,Year(getdate())) + '_2'
end
else
begin
set @tb_name = 'Y' + Convert(nvarchar,Year(getdate())) + '_1'
end
-- 判断数据表是否存在
if object_id(@tb_name,'U') is null
begin
exec ('CREATE TABLE [dbo].['+@tb_name+'] (
[SerialNo] [numeric](18, 0) IDENTITY (1, 1) not NULL ,
[ModelName] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
[BarcodeNo] [varchar] (30) COLLATE Chinese_PRC_CI_AS not NULL ,
[Station] [varchar] (5) COLLATE Chinese_PRC_CI_AS not NULL ,
[Information] [varchar] (4096) COLLATE Chinese_PRC_CI_AS not NULL ,
[Upload_Date] [datetime] default getdate() not NULL
) ON [PRIMARY]')
end
--查询数据是否存在,如果存在就更新插入日期,否则插入数据
exec('select @SerID=SerialNo from '+@tb_name+'where Information='+@XmlInfo)
if (@@rowcount > 0)
begin
exec ('update from '+@tb_name+'set Upload_Date=getdate() where SerialNo=@SerID')
set @Ret=1
end
else
begin
--插入数据
exec ('insert into '+@tb_name+' (ModelName,BarcodeNo,Station,Information)
values('''+@ModelName+''','''+@BarcodeNo+''','''+@Station+''','''+@XmlInfo+''') ')
set @Ret=1
end
end
go