if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_RECEIVEMESSAGE]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP2_RECEIVEMESSAGE]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_RECEIVEREPORT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP2_RECEIVEREPORT]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_SUBMIT_PROC]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP2_SUBMIT_PROC]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_MobileOrderRelation]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_MobileOrderRelation]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_MobileOrderRelation_Xxt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_MobileOrderRelation_Xxt]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_RECEIVEMESSAGE]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_RECEIVEMESSAGE]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_RECEIVEREPORT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_RECEIVEREPORT]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_SUBMIT]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_SUBMIT]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_SyncOrderRelationReq]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_SyncOrderRelationReq]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_SyncOrderRelationReq_Xxt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_SyncOrderRelationReq_Xxt]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP3_TimerClearSubmitPK]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPP3_TimerClearSubmitPK]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPPe2_RECEIVEMESSAGE]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPPe2_RECEIVEMESSAGE]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPPe2_SUBMITHISTORY]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[CMPPe2_SUBMITHISTORY]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_Deliver]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2_Deliver]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_Report]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2_Report]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_Submit]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2_Submit]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_Submit_Error]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2_Submit_Error]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2_Submit_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2_Submit_History]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2e_Deliver]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2e_Deliver]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2e_Submit]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2e_Submit]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2e_Submit_Error]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2e_Submit_Error]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CMPP2e_Submit_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[CMPP2e_Submit_History]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Deliver]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Deliver]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Deliver_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Deliver_History]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MobileOrderRelation]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MobileOrderRelation]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MobileOrderRelationHistory]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MobileOrderRelationHistory]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MobileOrderRelationHistory_Xxt]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MobileOrderRelationHistory_Xxt]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Report]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Report]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Report_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Report_History]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Submit]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Submit]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Submit_Error]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Submit_Error]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Submit_History]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Submit_History]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SubscribeServiceReq]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SubscribeServiceReq]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SubscribeServiceResp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SubscribeServiceResp]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SyncOrderRelationReq]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SyncOrderRelationReq]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SyncOrderRelationReq_Xxt]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SyncOrderRelationReq_Xxt]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UnSubscribeServiceReq]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UnSubscribeServiceReq]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UnSubscribeServiceResp]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UnSubscribeServiceResp]
GO

CREATE TABLE [dbo].[CMPP2_Deliver] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MO_Date] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Msg_Id] [bigint] NULL ,
	[Dest_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pid] [int] NULL ,
	[TP_udhi] [int] NULL ,
	[Msg_Fmt] [int] NULL ,
	[Src_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Registered_Delivery] [int] NULL ,
	[Msg_Length] [int] NULL ,
	[Msg_Content] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2_Report] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MO_Date] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Msg_Id] [bigint] NULL ,
	[Dest_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pid] [int] NULL ,
	[TP_udhi] [int] NULL ,
	[Msg_Fmt] [int] NULL ,
	[Src_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Registered_Delivery] [int] NULL ,
	[Msg_Length] [int] NULL ,
	[MT_Msg_Id] [bigint] NULL ,
	[Stat] [varchar] (8) COLLATE Chinese_PRC_CI_AS NULL ,
	[Submit_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Done_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[SMSC_sequence] [bigint] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2_Submit] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [int] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [int] NULL ,
	[Pk_number] [int] NULL ,
	[Registered_Delivery] [int] NULL ,
	[Msg_level] [int] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [int] NULL ,
	[Fee_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pId] [int] NULL ,
	[TP_udhi] [int] NULL ,
	[Msg_Fmt] [int] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Msg_Content] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2_Submit_Error] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [int] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [int] NULL ,
	[Pk_number] [int] NULL ,
	[Registered_Delivery] [int] NULL ,
	[Msg_level] [int] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [int] NULL ,
	[Fee_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pId] [int] NULL ,
	[TP_udhi] [int] NULL ,
	[Msg_Fmt] [int] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Msg_Content] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL ,
	[ErrorCode] [int] NULL ,
	[ErrorInfo] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[ErrorDate] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2_Submit_History] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [int] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [int] NULL ,
	[Pk_number] [int] NULL ,
	[Registered_Delivery] [int] NULL ,
	[Msg_level] [int] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [int] NULL ,
	[Fee_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pId] [int] NULL ,
	[TP_udhi] [int] NULL ,
	[Msg_Fmt] [int] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Msg_Content] [varchar] (300) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2e_Deliver] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[SourceAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestinationAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceType] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[ProtocolID] [int] NULL ,
	[MessageMode] [int] NULL ,
	[Priority] [int] NULL ,
	[DataCoding] [int] NULL ,
	[SMlength] [int] NULL ,
	[ShortMessage] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dates] [datetime] NULL ,
	[MessageID] [varchar] (64) COLLATE Chinese_PRC_CI_AS NULL ,
	[MessageStatus] [varchar] (3) COLLATE Chinese_PRC_CI_AS NULL ,
	[SubmitTime] [varchar] (12) COLLATE Chinese_PRC_CI_AS NULL ,
	[DoneTime] [varchar] (12) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2e_Submit] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [int] NULL ,
	[SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceType] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [int] NULL ,
	[InfoFee] [int] NULL ,
	[ProtocolID] [int] NULL ,
	[MessageMode] [int] NULL ,
	[Priority] [int] NULL ,
	[Validity] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[Schedule] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUserType] [int] NULL ,
	[FeeUser] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[SourceAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestinationAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DataCoding] [int] NULL ,
	[ShortMessage] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dates] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2e_Submit_Error] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [smallint] NULL ,
	[SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceType] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [int] NULL ,
	[InfoFee] [int] NULL ,
	[ProtocolID] [int] NULL ,
	[MessageMode] [int] NULL ,
	[Priority] [int] NULL ,
	[Validity] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[Schedule] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUserType] [int] NULL ,
	[FeeUser] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[SourceAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestinationAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DataCoding] [int] NULL ,
	[ShortMessage] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dates] [datetime] NULL ,
	[ErrorCode] [int] NULL ,
	[ErrorInfo] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[ErrorDate] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[CMPP2e_Submit_History] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [smallint] NULL ,
	[SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceType] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [int] NULL ,
	[InfoFee] [int] NULL ,
	[ProtocolID] [int] NULL ,
	[MessageMode] [int] NULL ,
	[Priority] [int] NULL ,
	[Validity] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[Schedule] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUserType] [int] NULL ,
	[FeeUser] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[SourceAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestinationAddress] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[DataCoding] [int] NULL ,
	[ShortMessage] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dates] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Deliver] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Msg_ID] [bigint] NULL ,
	[Dest_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pid] [smallint] NULL ,
	[TP_udhi] [smallint] NULL ,
	[Msg_Fmt] [smallint] NULL ,
	[Src_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_terminal_type] [smallint] NULL ,
	[Registered_Delivery] [smallint] NULL ,
	[Msg_Length] [smallint] NULL ,
	[Msg_Content] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Deliver_History] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Msg_ID] [bigint] NULL ,
	[Dest_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[TP_pid] [smallint] NULL ,
	[TP_udhi] [smallint] NULL ,
	[Msg_Fmt] [smallint] NULL ,
	[Src_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_terminal_type] [smallint] NULL ,
	[Registered_Delivery] [smallint] NULL ,
	[Msg_Length] [smallint] NULL ,
	[Msg_Content] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MobileOrderRelation] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Mobile] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[SPNumber] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[CMD] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MSG] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MobileOrderRelationHistory] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Mobile] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[SPNumber] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[CMD] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MSG] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[MobileOrderRelationHistory_Xxt] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Mobile] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[SPNumber] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[ServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[CMD] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MSG] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeMobile] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Report] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Msg_Id] [bigint] NULL ,
	[Stat] [varchar] (7) COLLATE Chinese_PRC_CI_AS NULL ,
	[Submit_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Done_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[SMSC_sequence] [int] NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Report_History] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Msg_Id] [bigint] NULL ,
	[Stat] [varchar] (7) COLLATE Chinese_PRC_CI_AS NULL ,
	[Submit_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Done_time] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[SMSC_sequence] [int] NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Submit] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [smallint] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [smallint] NULL ,
	[Pk_number] [smallint] NULL ,
	[Registered_Delivery] [smallint] NULL ,
	[Msg_level] [smallint] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [smallint] NULL ,
	[Fee_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_terminal_type] [smallint] NULL ,
	[TP_pId] [smallint] NULL ,
	[TP_udhi] [smallint] NULL ,
	[Msg_Fmt] [smallint] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_type] [smallint] NULL ,
	[Msg_Content] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Submit_Error] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [smallint] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [smallint] NULL ,
	[Pk_number] [smallint] NULL ,
	[Registered_Delivery] [smallint] NULL ,
	[Msg_level] [smallint] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [smallint] NULL ,
	[Fee_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_terminal_type] [smallint] NULL ,
	[TP_pId] [smallint] NULL ,
	[TP_udhi] [smallint] NULL ,
	[Msg_Fmt] [smallint] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_type] [smallint] NULL ,
	[Msg_Content] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[ErrorCode] [int] NULL ,
	[ErrorInfo] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
	[ErrorDate] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Submit_History] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MT_SequenceID] [bigint] NULL ,
	[MT_SendCount] [int] NULL ,
	[MT_BaseFetchFlag] [smallint] NULL ,
	[MT_Date] [datetime] NULL ,
	[Msg_Id] [bigint] NULL ,
	[Pk_total] [smallint] NULL ,
	[Pk_number] [smallint] NULL ,
	[Registered_Delivery] [smallint] NULL ,
	[Msg_level] [smallint] NULL ,
	[Service_Id] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_UserType] [smallint] NULL ,
	[Fee_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Fee_terminal_type] [smallint] NULL ,
	[TP_pId] [smallint] NULL ,
	[TP_udhi] [smallint] NULL ,
	[Msg_Fmt] [smallint] NULL ,
	[Msg_src] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeType] [varchar] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[ValId_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[At_Time] [varchar] (17) COLLATE Chinese_PRC_CI_AS NULL ,
	[Src_Id] [varchar] (21) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_Id] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_terminal_type] [smallint] NULL ,
	[Msg_Content] [varchar] (160) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SubscribeServiceReq] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Send_Address_DeviceType] [int] NULL ,
	[Send_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_Address_DeviceType] [int] NULL ,
	[Dest_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_UserIDType] [int] NULL ,
	[FeeUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_UserIDType] [int] NULL ,
	[DestUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_ServiceIDType] [int] NULL ,
	[Service_ID_SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_SPServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_AccessNo] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_FeatureStr] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[FeatureStr] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[MT_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[SubscribeServiceResp] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[hRet] [int] NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SyncOrderRelationReq] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Send_Address_DeviceType] [int] NULL ,
	[Send_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_Address_DeviceType] [int] NULL ,
	[Dest_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_UserIDType] [int] NULL ,
	[FeeUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_UserIDType] [int] NULL ,
	[DestUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[ActionID] [int] NULL ,
	[ActionReasonID] [int] NULL ,
	[SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[SPServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[AccessMode] [int] NULL ,
	[FeatureStr] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[SyncOrderRelationReq_Xxt] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Send_Address_DeviceType] [int] NULL ,
	[Send_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_Address_DeviceType] [int] NULL ,
	[Dest_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_UserIDType] [int] NULL ,
	[FeeUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_UserIDType] [int] NULL ,
	[DestUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[StudentID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[LinkID] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[ActionID] [int] NULL ,
	[ActionReasonID] [int] NULL ,
	[SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[SPServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[AccessMode] [int] NULL ,
	[FeatureStr] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[UnSubscribeServiceReq] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Send_Address_DeviceType] [int] NULL ,
	[Send_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Dest_Address_DeviceType] [int] NULL ,
	[Dest_Address_DeviceID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_UserIDType] [int] NULL ,
	[FeeUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[FeeUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_UserIDType] [int] NULL ,
	[DestUser_ID_MSISDN] [varchar] (32) COLLATE Chinese_PRC_CI_AS NULL ,
	[DestUser_ID_PseudoCode] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_ServiceIDType] [int] NULL ,
	[Service_ID_SPID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_SPServiceID] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_AccessNo] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Service_ID_FeatureStr] [text] COLLATE Chinese_PRC_CI_AS NULL ,
	[MT_Date] [datetime] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[UnSubscribeServiceResp] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[MsgType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[TransactionID] [varchar] (30) COLLATE Chinese_PRC_CI_AS NULL ,
	[Version] [varchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
	[hRet] [int] NULL ,
	[MO_Date] [datetime] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[CMPP2_Deliver] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP_Deliver] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2_Report] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2_Report] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2_Submit] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2_Submit] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2_Submit_Error] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2_Submit_Error] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2_Submit_History] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2_Submit_History] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2e_Deliver] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2e_Deliver] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2e_Submit] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2e_Submit] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2e_Submit_Error] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2e_Submit_Error] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2e_Submit_History] WITH NOCHECK ADD 
	CONSTRAINT [PK_CMPP2e_Submit_History] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Deliver] WITH NOCHECK ADD 
	CONSTRAINT [PK_Deliver] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Deliver_History] WITH NOCHECK ADD 
	CONSTRAINT [PK_Deliver_History] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MobileOrderRelation] WITH NOCHECK ADD 
	CONSTRAINT [PK_OrderRelationCommand] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MobileOrderRelationHistory] WITH NOCHECK ADD 
	CONSTRAINT [PK_MobileOrderRelationHistory] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MobileOrderRelationHistory_Xxt] WITH NOCHECK ADD 
	CONSTRAINT [PK_MobileOrderRelationHistory_Xxt] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Report] WITH NOCHECK ADD 
	CONSTRAINT [PK_Report] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Report_History] WITH NOCHECK ADD 
	CONSTRAINT [PK_Report_History] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Submit] WITH NOCHECK ADD 
	CONSTRAINT [PK_Submit] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Submit_Error] WITH NOCHECK ADD 
	CONSTRAINT [PK_Submit_Error] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Submit_History] WITH NOCHECK ADD 
	CONSTRAINT [PK_Submit_History] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SubscribeServiceReq] WITH NOCHECK ADD 
	CONSTRAINT [PK_SubscribeServiceReq] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SubscribeServiceResp] WITH NOCHECK ADD 
	CONSTRAINT [PK_SubscribeServiceResp] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SyncOrderRelationReq] WITH NOCHECK ADD 
	CONSTRAINT [PK_SyncOrderRelationReq] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SyncOrderRelationReq_Xxt] WITH NOCHECK ADD 
	CONSTRAINT [PK_SyncOrderRelationReq_Xxt] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[UnSubscribeServiceReq] WITH NOCHECK ADD 
	CONSTRAINT [PK_UnSubscribeServiceReq] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[UnSubscribeServiceResp] WITH NOCHECK ADD 
	CONSTRAINT [PK_UnSubscribeServiceResp] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[CMPP2_Deliver] ADD 
	CONSTRAINT [DF_CMPP2_Deliver_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[CMPP2_Report] ADD 
	CONSTRAINT [DF_CMPP2_Report_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[CMPP2_Submit] ADD 
	CONSTRAINT [DF_CMPP2_Submit_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_CMPP2_Submit_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_CMPP2_Submit_MT_BaseFetchFlag] DEFAULT (1) FOR [MT_BaseFetchFlag],
	CONSTRAINT [DF_CMPP2_Submit_MT_Date] DEFAULT (getdate()) FOR [MT_Date]
GO

ALTER TABLE [dbo].[CMPP2_Submit_Error] ADD 
	CONSTRAINT [DF_CMPP2_Submit_Error_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_CMPP2_Submit_Error_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_CMPP2_Submit_Error_MT_BaseFetchFlag] DEFAULT (1) FOR [MT_BaseFetchFlag],
	CONSTRAINT [DF_CMPP2_Submit_Error_MT_Date] DEFAULT (getdate()) FOR [MT_Date],
	CONSTRAINT [DF_CMPP2_Submit_Error_ErrorDate] DEFAULT (getdate()) FOR [ErrorDate]
GO

ALTER TABLE [dbo].[CMPP2_Submit_History] ADD 
	CONSTRAINT [DF_CMPP2_Submit_History_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_CMPP2_Submit_History_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_CMPP2_Submit_History_MT_BaseFetchFlag] DEFAULT (1) FOR [MT_BaseFetchFlag],
	CONSTRAINT [DF_CMPP2_Submit_History_MT_Date] DEFAULT (getdate()) FOR [MT_Date]
GO

ALTER TABLE [dbo].[Deliver] ADD 
	CONSTRAINT [DF_Deliver_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[Deliver_History] ADD 
	CONSTRAINT [DF_Deliver_History_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[MobileOrderRelation] ADD 
	CONSTRAINT [DF_MobileOrderRelation_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[MobileOrderRelationHistory] ADD 
	CONSTRAINT [DF_MobileOrderRelationHistory_Dates] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[MobileOrderRelationHistory_Xxt] ADD 
	CONSTRAINT [DF_MobileOrderRelationHistory_Xxt_Dates] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[Report] ADD 
	CONSTRAINT [DF_Report_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[Report_History] ADD 
	CONSTRAINT [DF_Report_History_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[Submit] ADD 
	CONSTRAINT [DF_Submit_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_Submit_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_Submit_MT_BaseFetchFlag] DEFAULT (1) FOR [MT_BaseFetchFlag],
	CONSTRAINT [DF_Submit_MT_Date] DEFAULT (getdate()) FOR [MT_Date],
	CONSTRAINT [DF_Submit_Msg_Id] DEFAULT (0) FOR [Msg_Id],
	CONSTRAINT [DF_Submit_Pk_total] DEFAULT (1) FOR [Pk_total],
	CONSTRAINT [DF_Submit_Pk_number] DEFAULT (1) FOR [Pk_number],
	CONSTRAINT [DF_Submit_Registered_Delivery] DEFAULT (0) FOR [Registered_Delivery],
	CONSTRAINT [DF_Submit_Msg_level] DEFAULT (7) FOR [Msg_level],
	CONSTRAINT [DF_Submit_Fee_UserType] DEFAULT (0) FOR [Fee_UserType],
	CONSTRAINT [DF_Submit_Fee_terminal_type] DEFAULT (0) FOR [Fee_terminal_type],
	CONSTRAINT [DF_Submit_TP_pId] DEFAULT (0) FOR [TP_pId],
	CONSTRAINT [DF_Submit_TP_udhi] DEFAULT (0) FOR [TP_udhi],
	CONSTRAINT [DF_Submit_Msg_Fmt] DEFAULT (15) FOR [Msg_Fmt],
	CONSTRAINT [DF_Submit_FeeCode] DEFAULT (0) FOR [FeeCode],
	CONSTRAINT [DF_Submit_ValId_Time] DEFAULT (0) FOR [ValId_Time],
	CONSTRAINT [DF_Submit_At_Time] DEFAULT (0) FOR [At_Time],
	CONSTRAINT [DF_Submit_Dest_terminal_type] DEFAULT (0) FOR [Dest_terminal_type]
GO

ALTER TABLE [dbo].[Submit_Error] ADD 
	CONSTRAINT [DF_Submit_Error_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_Submit_Error_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_Submit_Error_MT_Date] DEFAULT (getdate()) FOR [MT_Date],
	CONSTRAINT [DF_Submit_Error_Msg_Id] DEFAULT (0) FOR [Msg_Id],
	CONSTRAINT [DF_Submit_Error_Pk_total] DEFAULT (1) FOR [Pk_total],
	CONSTRAINT [DF_Submit_Error_Pk_number] DEFAULT (1) FOR [Pk_number],
	CONSTRAINT [DF_Submit_Error_Registered_Delivery] DEFAULT (0) FOR [Registered_Delivery],
	CONSTRAINT [DF_Submit_Error_Msg_level] DEFAULT (7) FOR [Msg_level],
	CONSTRAINT [DF_Submit_Error_Fee_UserType] DEFAULT (0) FOR [Fee_UserType],
	CONSTRAINT [DF_Submit_Error_Fee_terminal_type] DEFAULT (0) FOR [Fee_terminal_type],
	CONSTRAINT [DF_Submit_Error_TP_pId] DEFAULT (0) FOR [TP_pId],
	CONSTRAINT [DF_Submit_Error_TP_udhi] DEFAULT (0) FOR [TP_udhi],
	CONSTRAINT [DF_Submit_Error_Msg_Fmt] DEFAULT (15) FOR [Msg_Fmt],
	CONSTRAINT [DF_Submit_Error_FeeCode] DEFAULT (0) FOR [FeeCode],
	CONSTRAINT [DF_Submit_Error_ValId_Time] DEFAULT (0) FOR [ValId_Time],
	CONSTRAINT [DF_Submit_Error_At_Time] DEFAULT (0) FOR [At_Time],
	CONSTRAINT [DF_Submit_Error_Dest_terminal_type] DEFAULT (0) FOR [Dest_terminal_type],
	CONSTRAINT [DF_Submit_Error_ErrorDate] DEFAULT (getdate()) FOR [ErrorDate]
GO

ALTER TABLE [dbo].[Submit_History] ADD 
	CONSTRAINT [DF_Submit_History_MT_SequenceID] DEFAULT ((-1)) FOR [MT_SequenceID],
	CONSTRAINT [DF_Submit_History_MT_SendCount] DEFAULT (0) FOR [MT_SendCount],
	CONSTRAINT [DF_Submit_History_MT_Date] DEFAULT (getdate()) FOR [MT_Date],
	CONSTRAINT [DF_Submit_History_Msg_Id] DEFAULT (0) FOR [Msg_Id],
	CONSTRAINT [DF_Submit_History_Pk_total] DEFAULT (1) FOR [Pk_total],
	CONSTRAINT [DF_Submit_History_Pk_number] DEFAULT (1) FOR [Pk_number],
	CONSTRAINT [DF_Submit_History_Registered_Delivery] DEFAULT (0) FOR [Registered_Delivery],
	CONSTRAINT [DF_Submit_History_Msg_level] DEFAULT (7) FOR [Msg_level],
	CONSTRAINT [DF_Submit_History_Fee_UserType] DEFAULT (0) FOR [Fee_UserType],
	CONSTRAINT [DF_Submit_History_Fee_terminal_type] DEFAULT (0) FOR [Fee_terminal_type],
	CONSTRAINT [DF_Submit_History_TP_pId] DEFAULT (0) FOR [TP_pId],
	CONSTRAINT [DF_Submit_History_TP_udhi] DEFAULT (0) FOR [TP_udhi],
	CONSTRAINT [DF_Submit_History_Msg_Fmt] DEFAULT (15) FOR [Msg_Fmt],
	CONSTRAINT [DF_Submit_History_FeeCode] DEFAULT (0) FOR [FeeCode],
	CONSTRAINT [DF_Submit_History_ValId_Time] DEFAULT (0) FOR [ValId_Time],
	CONSTRAINT [DF_Submit_History_At_Time] DEFAULT (0) FOR [At_Time],
	CONSTRAINT [DF_Submit_History_Dest_terminal_type] DEFAULT (0) FOR [Dest_terminal_type]
GO

ALTER TABLE [dbo].[SubscribeServiceReq] ADD 
	CONSTRAINT [DF_SubscribeServiceReq_MT_Date] DEFAULT (getdate()) FOR [MT_Date]
GO

ALTER TABLE [dbo].[SubscribeServiceResp] ADD 
	CONSTRAINT [DF_SubscribeServiceResp_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[SyncOrderRelationReq] ADD 
	CONSTRAINT [DF_SyncOrderRelationReq_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[SyncOrderRelationReq_Xxt] ADD 
	CONSTRAINT [DF_SyncOrderRelationReq_Xxt_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

ALTER TABLE [dbo].[UnSubscribeServiceReq] ADD 
	CONSTRAINT [DF_UnSubscribeServiceReq_MT_Date] DEFAULT (getdate()) FOR [MT_Date]
GO

ALTER TABLE [dbo].[UnSubscribeServiceResp] ADD 
	CONSTRAINT [DF_UnSubscribeServiceResp_MO_Date] DEFAULT (getdate()) FOR [MO_Date]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE     PROCEDURE CMPP2_RECEIVEMESSAGE
  @Msg_Id	bigint,
  @Dest_Id	varchar(21),
  @Service_Id	varchar(10),
  @TP_pid	int,
  @TP_udhi	int,
  @Msg_Fmt	int,
  @Src_terminal_Id	varchar(21),
  @Registered_Delivery	int,
  @Msg_Length	int,
  @Msg_Content	varchar(300) 
AS
 
  INSERT INTO CMPP2_DELIVER
  (
   Msg_Id,Dest_Id, Service_Id,TP_pid,TP_udhi,Msg_Fmt,Src_terminal_Id,
   Registered_Delivery,Msg_Length,Msg_Content 
  )
  VALUES
  (
   @Msg_Id,@Dest_Id, @Service_Id,@TP_pid,@TP_udhi,@Msg_Fmt,@Src_terminal_Id,
   @Registered_Delivery,@Msg_Length,@Msg_Content 
  )

  



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



create  PROCEDURE CMPP2_RECEIVEREPORT
  @Msg_Id	bigint,
  @Dest_Id	varchar(21),
  @Service_Id	varchar(10),
  @TP_pid	int,
  @TP_udhi	int,
  @Msg_Fmt	int,
  @Src_terminal_Id	varchar(21),
  @Registered_Delivery	int,
  @Msg_Length	int,
  @MT_Msg_Id	bigint,
  @Stat		varchar(8),
  @Submit_time	varchar(10),
  @Done_time	varchar(10),
  @Dest_terminal_Id	varchar(21),
  @SMSC_sequence	bigint

AS
   INSERT INTO CMPP2_REPORT
  (
   Msg_Id,Dest_Id, Service_Id,TP_pid,TP_udhi,Msg_Fmt,Src_terminal_Id,
   Registered_Delivery,Msg_Length,MT_Msg_Id,Stat,Submit_time,
   Done_time,Dest_terminal_Id,SMSC_sequence 
  )
  VALUES
  (
   @Msg_Id,@Dest_Id, @Service_Id,@TP_pid,@TP_udhi,@Msg_Fmt,@Src_terminal_Id,
   @Registered_Delivery,@Msg_Length,@MT_Msg_Id,@Stat,@Submit_time, 
   @Done_time,@Dest_terminal_Id,@SMSC_sequence 
  )



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE  PROC CMPP2_SUBMIT_PROC
  @Msg_Id bigint,
  @Pk_total smallint,
  @Pk_number smallint,
  @Registered_Delivery smallint,
  @Msg_level smallint,
  @Service_Id varchar(11),
  @Fee_UserType smallint,
  @Fee_terminal_Id varchar(21),
  @TP_pId smallint,
  @TP_udhi smallint,
  @Msg_Fmt smallint,
  @Msg_src varchar(6),
  @FeeType varchar(2),
  @FeeCode varchar(6),
  @ValId_Time varchar(17),
  @At_Time varchar(17),
  @Src_Id varchar (21),
  @Dest_terminal_Id varchar(21),
  @Msg_Content varchar(300)

AS
  DECLARE @MT_BaseFetchFlag  smallint
  SET @MT_BaseFetchFlag = 1


  INSERT INTO CMPP3..CMPP2_Submit(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,
                     Service_Id,Fee_UserType,Fee_terminal_Id,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,
                     ValId_Time,At_Time,Src_Id,Dest_terminal_Id,Msg_Content) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,
                     @Fee_UserType,@Fee_terminal_Id,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, 
                     @ValId_Time,@At_Time,@Src_Id,@Dest_terminal_Id,@Msg_Content)

  --历史记录
  INSERT INTO CMPP3..CMPP2_Submit_History(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,
                     Service_Id,Fee_UserType,Fee_terminal_Id,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,ValId_Time,
                     At_Time,Src_Id,Dest_terminal_Id,Msg_Content) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,@Fee_UserType,
                     @Fee_terminal_Id,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, @ValId_Time,
                     @At_Time,@Src_Id,@Dest_terminal_Id,@Msg_Content)






GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO










CREATE        PROC CMPP3_MobileOrderRelation
  @Mobile VarChar(32),
  @SPNumber VarChar(32),
  @ServiceID VarChar(10),
  @CMD VarChar(20),
  @MSG VarChar(160)
AS
  -- 写入历史表
  INSERT INTO MobileOrderRelationHistory(Mobile,SPNumber,ServiceID,CMD,MSG) VALUES
                                        (@Mobile,@SPNumber,@ServiceID,@CMD,@MSG)    

  ----------------------------------------------------------------------------
  --ADD PROC TO DO
  ----------------------------------------------------------------------------

  INSERT INTO MobileOrderRelation(Mobile,SPNumber,ServiceID,CMD,MSG) VALUES
                                        (@Mobile,@SPNumber,@ServiceID,@CMD,@MSG)    










GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO






CREATE PROCEDURE [dbo].[CMPP3_MobileOrderRelation_Xxt]
  @Mobile VarChar(32),
  @SPNumber VarChar(32),
  @ServiceID VarChar(10),
  @CMD VarChar(20),
  @MSG VarChar(160),
  @FeeMobile VarChar(32)
AS
  -- 写入历史表
  INSERT INTO MobileOrderRelationHistory_Xxt(Mobile,SPNumber,ServiceID,CMD,MSG,FeeMobile) VALUES
                                        (@Mobile,@SPNumber,@ServiceID,@CMD,@MSG,@FeeMobile)    




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
















/****** Object:  Stored Procedure dbo.CMPP3_RECEIVEMESSAGE    Script Date: 2004-06-30 16:14:20 ******/
CREATE             PROCEDURE CMPP3_RECEIVEMESSAGE
   @Msg_ID bigint,
   @Dest_Id varchar(21),
   @Service_Id varchar(10),
   @TP_pid smallint,
   @TP_udhi smallint,
   @Msg_Fmt smallint,
   @Src_terminal_Id varchar(32),
   @Src_terminal_type smallint,
   @Registered_Delivery smallint,
   @Msg_Length smallint,
   @Msg_Content varchar(200),
   @LinkID varchar(20)
AS
   INSERT INTO Deliver(Msg_ID,Dest_Id,Service_Id,TP_pid,TP_udhi,Msg_Fmt,Src_terminal_Id,Src_terminal_type,Registered_Delivery,Msg_Length,Msg_Content,LinkID) 
   VALUES (@Msg_ID,@Dest_Id,@Service_Id,@TP_pid,@TP_udhi,@Msg_Fmt,@Src_terminal_Id,@Src_terminal_type,@Registered_Delivery,@Msg_Length,@Msg_Content,@LinkID)


  IF @Msg_Content = 'CMCCTEST'
  BEGIN
    SET @Msg_Content = '浙江,华海科技,01616,911132,'
    SET @Msg_Content = @Msg_Content + DATENAME(yyyy,GetDate()) + '年' + DATENAME(mm,GetDate())   + '月'  
    SET @Msg_Content = @Msg_Content + DATENAME(dd,GetDate())   + '日' + DATENAME(hh,GetDate())   + '时'
    SET @Msg_Content = @Msg_Content + DATENAME(mi,GetDate())   + '分' + DATENAME(ss,GetDate())   + '秒'
    SET @Msg_Content = @Msg_Content + DATENAME(weekday,GetDate())

    --EXEC CMPP3_SUBMIT 0,1,1,0,7,'CMCCTEST',0,'',0,0,0,15,'911132','02','1',0,0,'01616',@Src_terminal_Id,0,@Msg_Content,@LinkID
    RETURN
  END
 
  
  EXEC CMPP3_MobileOrderRelation  @Src_terminal_Id,@Dest_Id,@Service_Id,'MSG',@Msg_Content














GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




/****** Object:  Stored Procedure dbo.CMPP3_RECEIVEREPORT    Script Date: 2004-06-30 16:14:20 ******/
CREATE PROCEDURE CMPP3_RECEIVEREPORT
  @Msg_Id bigint,
  @Stat varchar(7),
  @Submit_time varchar(10),
  @Done_time varchar(10),
  @Dest_terminal_Id varchar(32),
  @SMSC_sequence int
AS
  INSERT INTO Report(Msg_Id,Stat,Submit_time,Done_time,Dest_terminal_Id,SMSC_sequence)	
  VALUES (@Msg_Id,@Stat,@Submit_time,@Done_time,@Dest_terminal_Id,@SMSC_sequence)




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE   PROC CMPP3_SUBMIT
  @Msg_Id bigint,
  @Pk_total smallint,
  @Pk_number smallint,
  @Registered_Delivery smallint,
  @Msg_level smallint,
  @Service_Id varchar(11),
  @Fee_UserType smallint,
  @Fee_terminal_Id varchar(32),
  @Fee_terminal_type smallint,
  @TP_pId smallint,
  @TP_udhi smallint,
  @Msg_Fmt smallint,
  @Msg_src varchar(6),
  @FeeType varchar(2),
  @FeeCode varchar(6),
  @ValId_Time varchar(17),
  @At_Time varchar(17),
  @Src_Id varchar (21),
  @Dest_terminal_Id varchar(32),
  @Dest_terminal_type smallint,
  @Msg_Content varchar(160),
  @LinkID varchar(20)
AS
  DECLARE @MT_BaseFetchFlag  smallint
  SET @MT_BaseFetchFlag = 1

  --  与 misc系统分流
  if (substring(@Src_Id,1,5) = '06161')
  begin
     -- 发送队列
  INSERT INTO CMPP3_JxtWeb..Submit(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,Service_Id,Fee_UserType,
                     Fee_terminal_Id,Fee_terminal_type,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,ValId_Time,
                     At_Time,Src_Id,Dest_terminal_Id,Dest_terminal_type,Msg_Content,LinkID) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,@Fee_UserType,
                     @Fee_terminal_Id,@Fee_terminal_type,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, @ValId_Time,
                     @At_Time,@Src_Id,@Dest_terminal_Id,@Dest_terminal_type,@Msg_Content,@LinkID)

  --历史记录
  INSERT INTO CMPP3_JxtWeb..Submit_History(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,Service_Id,Fee_UserType,
                     Fee_terminal_Id,Fee_terminal_type,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,ValId_Time,
                     At_Time,Src_Id,Dest_terminal_Id,Dest_terminal_type,Msg_Content,LinkID) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,@Fee_UserType,
                     @Fee_terminal_Id,@Fee_terminal_type,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, @ValId_Time,
                     @At_Time,@Src_Id,@Dest_terminal_Id,@Dest_terminal_type,@Msg_Content,@LinkID)


   
  return  
  end
  -- 发送队列
  INSERT INTO Submit(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,Service_Id,Fee_UserType,
                     Fee_terminal_Id,Fee_terminal_type,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,ValId_Time,
                     At_Time,Src_Id,Dest_terminal_Id,Dest_terminal_type,Msg_Content,LinkID) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,@Fee_UserType,
                     @Fee_terminal_Id,@Fee_terminal_type,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, @ValId_Time,
                     @At_Time,@Src_Id,@Dest_terminal_Id,@Dest_terminal_type,@Msg_Content,@LinkID)

  --历史记录
  INSERT INTO Submit_History(MT_BaseFetchFlag,Msg_Id,Pk_total,Pk_number,Registered_Delivery,Msg_level,Service_Id,Fee_UserType,
                     Fee_terminal_Id,Fee_terminal_type,TP_pId,TP_udhi,Msg_Fmt,Msg_src,FeeType,FeeCode,ValId_Time,
                     At_Time,Src_Id,Dest_terminal_Id,Dest_terminal_type,Msg_Content,LinkID) 
                     VALUES
                    (@MT_BaseFetchFlag,@Msg_Id,@Pk_total,@Pk_number,@Registered_Delivery,@Msg_level,@Service_Id,@Fee_UserType,
                     @Fee_terminal_Id,@Fee_terminal_type,@TP_pId,@TP_udhi,@Msg_Fmt,@Msg_src,@FeeType,@FeeCode, @ValId_Time,
                     @At_Time,@Src_Id,@Dest_terminal_Id,@Dest_terminal_type,@Msg_Content,@LinkID)






GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO





CREATE  PROCEDURE [dbo].[CMPP3_SyncOrderRelationReq] 
(	
      @MsgType  varchar(30),
      @TransactionID  varchar(30),
      @Version  varchar(10),
      @Send_Address_DeviceType  int,
      @Send_Address_DeviceID  varchar(30),
      @Dest_Address_DeviceType int,
      @Dest_Address_DeviceID  varchar(30),
      @FeeUser_ID_UserIDType  int,
      @FeeUser_ID_MSISDN  varchar(32),
      @FeeUser_ID_PseudoCode  varchar(100),
      @DestUser_ID_UserIDType int,
      @DestUser_ID_MSISDN  varchar(32),
      @DestUser_ID_PseudoCode varchar(100),
      @LinkID varchar(20),
      @ActionID int,
      @ActionReasonID int,
      @SPID varchar(10),
      @SPServiceID varchar(10),
      @AccessMode int,
      @FeatureStr varchar(100)

)
AS

declare @Mobile varchar(32)
declare @SPNumber varchar(32)
declare @ServiceID varchar(10)
declare @CMD varchar(20)
declare @MSG varchar(160)

INSERT INTO SyncOrderRelationReq(MsgType,TransactionID,Version,Send_Address_DeviceType,Send_Address_DeviceID,Dest_Address_DeviceType,Dest_Address_DeviceID,FeeUser_ID_UserIDType,FeeUser_ID_MSISDN,FeeUser_ID_PseudoCode,DestUser_ID_UserIDType,DestUser_ID_MSISDN,DestUser_ID_PseudoCode,LinkID,ActionID,ActionReasonID,SPID,SPServiceID,AccessMode,FeatureStr) VALUES 
                                (@MsgType,@TransactionID,@Version,@Send_Address_DeviceType,@Send_Address_DeviceID,@Dest_Address_DeviceType,@Dest_Address_DeviceID,@FeeUser_ID_UserIDType,@FeeUser_ID_MSISDN,@FeeUser_ID_PseudoCode,@DestUser_ID_UserIDType,@DestUser_ID_MSISDN,@DestUser_ID_PseudoCode,@LinkID,@ActionID,@ActionReasonID,@SPID,@SPServiceID,@AccessMode,@FeatureStr)
 
  
------------------------ 用户手机
if (@DestUser_ID_UserIDType = 1)    --用户手机标识                        
begin
  select @Mobile = @DestUser_ID_MSISDN
end

if (@DestUser_ID_UserIDType = 2)       --用户伪码标识                     
begin
  ---select @Mobile = @DestUser_ID_PseudoCode
  select @Mobile = @DestUser_ID_MSISDN
end

if (@DestUser_ID_UserIDType = 3)     --两者同时标识                       
begin
  select @Mobile = @DestUser_ID_MSISDN
  select @SPNumber = @DestUser_ID_PseudoCode   --规定SP号存伪码
end
-----------------------

-----------------------服务代码
select @ServiceID = @SPServiceID
-----------------------

-----------------------命令定义
if (@ActionID = 1)  
begin
   select @CMD = 'BStart'   --开通服务
end

if (@ActionID = 2)
begin
   select @CMD = 'BStop'    --停止服务
end

if (@ActionID = 3)
begin
   select @CMD = 'BActive'  --激活服务
end

if (@ActionID = 4)
begin
   select @CMD = 'BPause'  --暂停服务
end
-----------------------

Exec CMPP3_MobileOrderRelation @Mobile,@SPNumber,@ServiceID,@CMD,@MSG





GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE PROCEDURE [dbo].[CMPP3_SyncOrderRelationReq_Xxt] 
(	
      @MsgType  varchar(30),
      @TransactionID  varchar(30),
      @Version  varchar(10),
      @Send_Address_DeviceType  int,
      @Send_Address_DeviceID  varchar(30),
      @Dest_Address_DeviceType int,
      @Dest_Address_DeviceID  varchar(30),
      @FeeUser_ID_UserIDType  int,
      @FeeUser_ID_MSISDN  varchar(32),
      @FeeUser_ID_PseudoCode  varchar(100),
      @DestUser_ID_UserIDType int,
      @DestUser_ID_MSISDN  varchar(32),
      @DestUser_ID_PseudoCode varchar(100),
      @StudentID varchar(20),
      @LinkID varchar(20),
      @ActionID int,
      @ActionReasonID int,
      @SPID varchar(10),
      @SPServiceID varchar(10),
      @AccessMode int,
      @FeatureStr varchar(100)

)
AS

declare @Mobile varchar(32)
declare @FeeMobile varchar(32)
declare @SPNumber varchar(32)
declare @ServiceID varchar(10)
declare @CMD varchar(20)
declare @MSG varchar(160)


INSERT INTO SyncOrderRelationReq_Xxt(MsgType,TransactionID,Version,Send_Address_DeviceType,Send_Address_DeviceID,Dest_Address_DeviceType,Dest_Address_DeviceID,FeeUser_ID_UserIDType,FeeUser_ID_MSISDN,FeeUser_ID_PseudoCode,DestUser_ID_UserIDType,DestUser_ID_MSISDN,DestUser_ID_PseudoCode,StudentID,LinkID,ActionID,ActionReasonID,SPID,SPServiceID,AccessMode,FeatureStr) VALUES 
                                (@MsgType,@TransactionID,@Version,@Send_Address_DeviceType,@Send_Address_DeviceID,@Dest_Address_DeviceType,@Dest_Address_DeviceID,@FeeUser_ID_UserIDType,@FeeUser_ID_MSISDN,@FeeUser_ID_PseudoCode,@DestUser_ID_UserIDType,@DestUser_ID_MSISDN,@DestUser_ID_PseudoCode,@StudentID,@LinkID,@ActionID,@ActionReasonID,@SPID,@SPServiceID,@AccessMode,@FeatureStr)
 
  
------------------------ 用户手机
if (@DestUser_ID_UserIDType = 1)    --用户手机标识                        
begin
  select @Mobile = @DestUser_ID_MSISDN
end

if (@DestUser_ID_UserIDType = 2)       --用户伪码标识                     
begin
  select @Mobile = @DestUser_ID_PseudoCode
end

if (@DestUser_ID_UserIDType = 3)     --两者同时标识                       
begin
  select @Mobile = @DestUser_ID_MSISDN
  select @SPNumber = @DestUser_ID_PseudoCode   --规定SP号存伪码
end
-----------------------

----------------------付费手机（为空免费）
if (@FeeUser_ID_UserIDType = 1)    --用户手机标识                        
begin
  select @FeeMobile = @FeeUser_ID_MSISDN
end

if (@FeeUser_ID_UserIDType = 2)       --用户伪码标识                     
begin
  select @FeeMobile = @FeeUser_ID_PseudoCode
end



-----------------------服务代码
select @ServiceID = @SPServiceID

-- 用户免费 业务代码规定为 AF ,BF
if (@FeeMobile = '') OR (@FeeMobile = null)
begin
  select @ServiceID = @ServiceID + 'F'
end
-----------------------

-----------------------命令定义
if (@ActionID = 1)  
begin
   select @CMD = 'BStart'   --开通服务
end

if (@ActionID = 2)
begin
   select @CMD = 'BStop'    --停止服务
end

if (@ActionID = 3)
begin
   select @CMD = 'BActive'  --激活服务
end

if (@ActionID = 4)
begin
   select @CMD = 'BPause'  --暂停服务
end
-----------------------

Exec CMPP3_MobileOrderRelation_Xxt @Mobile,@SPNumber,@ServiceID,@CMD,@StudentID,@FeeMobile  --MSG暂存StudentID
 




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE  PROC CMPP3_TimerClearSubmitPK
AS

IF EXISTS(SELECT * FROM CMPP3_JxtWeb..Submit WHERE MT_SendCount <> 0)
BEGIN
  DELETE FROM CMPP3_JxtWeb..Submit  WHERE MT_SendCount <> 0
END


IF EXISTS(SELECT * FROM Submit WHERE MT_SendCount <> 0)
BEGIN
  DELETE FROM Submit  WHERE MT_SendCount <> 0
END





GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE  PROCEDURE CMPPe2_RECEIVEMESSAGE


  @SourceAddress	varchar(21),
  @DestinationAddress	varchar(21),
  @ServiceType	varchar(10),
  @ProtocolID	int,
  @MessageMode	int,
  @Priority	int,
  @DataCoding	int,
  @SMlength	int,
  @ShortMessage	varchar(200),
  @MessageID	varchar(64),
  @MessageStatus	varchar(3),
  @SubmitTime	varchar(12),
  @DoneTime	varchar(12)
AS
 
  INSERT INTO CMPP2e_Deliver
  (
    SourceAddress,DestinationAddress,ServiceType,ProtocolID,MessageMode,Priority,
    DataCoding,SMlength,ShortMessage,MessageID,MessageStatus,SubmitTime,DoneTime 
   )
VALUES
  (
    @SourceAddress,@DestinationAddress,@ServiceType,@ProtocolID,@MessageMode,@Priority,
    @DataCoding,@SMlength,@ShortMessage,@MessageID,@MessageStatus,@SubmitTime,@DoneTime
   )



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROC CMPPe2_SUBMITHISTORY
  @MT_SequenceID	bigint,
  @MT_SendCount		int,	
  @MT_BaseFetchFlag	smallint,
  @SPID			varchar(10),
  @ServiceType		varchar(10),
  @FeeType		int,
  @InfoFee		int,
  @ProtocolID		int,
  @MessageMode		int,
  @Priority		int,
  @Validity		varchar(21),
  @Schedule		varchar(21),
  @FeeUserType		int,
  @FeeUser		varchar(21),
  @SourceAddress	varchar(21),
  @DestinationAddress	varchar(21),
  @DataCoding		int,
  @ShortMessage		varchar(200)
AS

  INSERT INTO CMPP2e_Submit_History
              (
                MT_SequenceID, 
                MT_SendCount, 
                MT_BaseFetchFlag, 
                SPID, 
                ServiceType, 
                FeeType, 
                InfoFee, 
                ProtocolID, 
                MessageMode, 
                Priority, 
                Validity, 
                Schedule, 
                FeeUserType,
                FeeUser, 
                SourceAddress, 
                DestinationAddress, 
                DataCoding, 
                ShortMessage
              )
  VALUES      (
                @MT_SequenceID,
                @MT_SendCount, 
                @MT_BaseFetchFlag, 
                @SPID, 
                @ServiceType, 
                @FeeType, 
                @InfoFee, 
                @ProtocolID, 
                @MessageMode, 
                @Priority, 
                @Validity, 
                @Schedule, 
                @FeeUserType,
                @FeeUser, 
                @SourceAddress, 
                @DestinationAddress, 
                @DataCoding, 
                @ShortMessage
              )

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

