BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_agentcallid', N'Tmp_qw_agentid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_agentid_1', N'qw_agentid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_ownercallid', N'Tmp_qw_ownerid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_ownerid_1', N'qw_ownerid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_wgroupcallid', N'Tmp_qw_workgroupid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_workgroupid_1', N'qw_workgroupid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_escwgroupcallid', N'Tmp_qw_escworkgroupid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_escworkgroupid_1', N'qw_escworkgroupid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_productcallid', N'Tmp_qw_productid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_productid_1', N'qw_productid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_componentcallid', N'Tmp_qw_componentid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_componentid_1', N'qw_componentid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_buildverscallid', N'Tmp_qw_repbuildversionid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_repbuildversionid_1', N'qw_repbuildversionid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_resverscallid', N'Tmp_qw_resbuildversionid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_resbuildversionid_1', N'qw_resbuildversionid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_categcallid', N'Tmp_qw_category_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_category_1', N'qw_category', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_subcatcallid', N'Tmp_qw_subcategory_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_subcategory_1', N'qw_subcategory', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_reasoncallid', N'Tmp_qw_reasoncode_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_reasoncode_1', N'qw_reasoncode', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_repenvcallid', N'Tmp_qw_repenvironmentid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_repenvironmentid_1', N'qw_repenvironmentid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_testenvcallid', N'Tmp_qw_testenvironmentid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_testenvironmentid_1', N'qw_testenvironmentid', 'COLUMN' 
GO
COMMIT
GO

BEGIN TRANSACTION
GO
EXECUTE sp_rename N'dbo.QW_TICKET.qw_customercallid', N'Tmp_qw_customerid_1', 'COLUMN' 
GO
EXECUTE sp_rename N'dbo.QW_TICKET.Tmp_qw_customerid_1', N'qw_customerid', 'COLUMN' 
GO
COMMIT
GO

----------- Clear history tables --------------

DELETE FROM QX_HIS_TBLFIELD
GO
DELETE FROM QX_HIS_FIELD
GO
DELETE FROM QX_HIS_TABLE
GO

--------- Add extra fields to QW_TICKET ----------
ALTER TABLE [dbo].[QW_TICKET] DROP COLUMN [qw_probtypecallid] 
GO

ALTER TABLE [dbo].[QW_TICKET] ADD [qw_otherreason] VARCHAR(1000) NULL 
GO

-- all new update scripts must include a line like this:
UPDATE QX_SYS_PROP SET PROP_VAL = '018' WHERE (PROP_ID = 'DB_APP_VERSION');
