USE [ROMICO-CTI]
GO

/****** Object:  Table [dbo].[CallClassification]    Script Date: 06/09/2011 09:52:01 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[CallClassification](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[ProtocolID] [bigint] NOT NULL,
	[TimeWaitConnect] [bigint] NOT NULL,
	[CallerInfo] [varchar](50) NOT NULL,
	[CalledInfo] [varchar](50) NOT NULL,
	[CalledDestination] [varchar](50) NOT NULL,
	[Subject] [varchar](50) NOT NULL,
	[SubjectFirstCall] [varchar](8) NOT NULL,
	[Reason] [varchar](50) NOT NULL,
	[NextStep] [varchar](25) NOT NULL,
	[Description] [text] NULL,
 CONSTRAINT [PK_CallClassification] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[CallClassification] ADD  CONSTRAINT [DF_CallClassification_Duration]  DEFAULT ((0)) FOR [TimeWaitConnect]
GO

CREATE VIEW [dbo].[ProtocolCallClassification]
AS
SELECT     dbo.CallClassification.Id, dbo.CallClassification.ProtocolID, dbo.CallClassification.TimeWaitConnect, dbo.CallClassification.CallerInfo, 
                      dbo.CallClassification.CalledInfo, dbo.CallClassification.CalledDestination, dbo.CallClassification.Subject, dbo.CallClassification.SubjectFirstCall, 
                      dbo.CallClassification.Reason, dbo.CallClassification.NextStep, dbo.CallClassification.Description, dbo.Protocol.ID AS ProtocolTableID, dbo.Protocol.hCall, 
                      dbo.Protocol.Benutzer, dbo.Protocol.Line, dbo.Protocol.MasterLine, dbo.Protocol.FollowMe, dbo.Protocol.Origin, dbo.Protocol.Telefonnummer, 
                      dbo.Protocol.CompletePhoneNumber, dbo.Protocol.CalledID, dbo.Protocol.TimeStart, dbo.Protocol.TimeConnect, dbo.Protocol.TimeEnd, dbo.Protocol.Start, 
                      dbo.Protocol.Connect, dbo.Protocol.[End], dbo.Protocol.Status, dbo.Protocol.Duration, dbo.Protocol.Provider, dbo.Protocol.Price, dbo.Protocol.[Percent], 
                      dbo.Protocol.UserOnline, dbo.Protocol.Abgeholt, dbo.Protocol.CPhoneNumber, dbo.Protocol.Outgoing, dbo.Protocol.CallType, dbo.Protocol.RedirectingID, 
                      dbo.Protocol.RedirectionID, dbo.Protocol.Show, dbo.Protocol.Name1, dbo.Protocol.Name2, dbo.Protocol.Company, dbo.Protocol.LastChange, 
                      dbo.Protocol.UserGroupID, dbo.Protocol.UserFirmID, dbo.Protocol.Marked, dbo.Protocol.Email, dbo.Protocol.ExtraField, dbo.Protocol.RedirectChecked, 
                      dbo.Protocol.Redirected, dbo.Protocol.Picked, dbo.Protocol.RedDestLine, dbo.Protocol.RedDestRecId, dbo.Protocol.CallBackHoursRange, 
                      dbo.Protocol.CallBackFoundOutgoing, dbo.Protocol.CallBackFoundRecId, dbo.Protocol.MailBoxFile, dbo.Protocol.MailBoxFileListened, dbo.Protocol.RedSourceRecId, 
                      dbo.Protocol.TargetID
FROM         dbo.CallClassification INNER JOIN
                      dbo.Protocol ON dbo.CallClassification.ProtocolID = dbo.Protocol.ID

GO