if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardRechargeRecord') and name='Mcrr_OrderPerson') begin alter table dbo.tb_ErpMemberCardRechargeRecord add Mcrr_OrderPerson nvarchar(20) NULL end GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_PackagePrice') begin alter table dbo.tb_ErpMemberCardPayment add Mcpt_PackagePrice decimal(18,2) NULL end GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_Discount') begin alter table dbo.tb_ErpMemberCardPayment add Mcpt_Discount decimal(18,2) NULL end GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardPayment') and name='Mcpt_OrderPerson') begin alter table dbo.tb_ErpMemberCardPayment add Mcpt_OrderPerson nvarchar(20) NULL end GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_OpenCardAoumnt') begin alter table tb_ErpMemberCardGradeSet add Mcgs_OpenCardAoumnt nvarchar(200) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_OpenCardAoumnt')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会开卡金' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_OpenCardAoumnt' GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_ReturnNeededPoints') begin alter table tb_ErpMemberCardGradeSet add Mcgs_ReturnNeededPoints nvarchar(200) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_ReturnNeededPoints')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会返还所需积分' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_ReturnNeededPoints' GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardGradeSet') and name='Mcgs_ReturnAoumnt') begin alter table tb_ErpMemberCardGradeSet add Mcgs_ReturnAoumnt nvarchar(200) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardGradeSet', N'COLUMN',N'Mcgs_ReturnAoumnt')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'新摄会返还金额' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardGradeSet', @level2type=N'COLUMN',@level2name=N'Mcgs_ReturnAoumnt' GO --2015-06-28 更新--- if not exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_DianQingDate') begin alter table tb_ErpCompanyInfo add Company_DianQingDate nvarchar(200) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpCompanyInfo', N'COLUMN',N'Company_DianQingDate')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'店庆日期' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCompanyInfo', @level2type=N'COLUMN',@level2name=N'Company_DianQingDate' GO if not exists (select * from syscolumns where id=object_id('tb_ErpMemberCardPointsRuleSet') and name='Mcprs_Remark') begin alter table tb_ErpMemberCardPointsRuleSet add Mcprs_Remark nvarchar(200) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpMemberCardPointsRuleSet', N'COLUMN',N'Mcprs_Remark')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpMemberCardPointsRuleSet', @level2type=N'COLUMN',@level2name=N'Mcprs_Remark' GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='订单收款') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'订单收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='现金支出') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'现金支出', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='其它收入') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'其它收入', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表日') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表日', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表月') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表月', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='财务报表年') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'财务报表年', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'1', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='拍照明细表') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'拍照明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='拍照派工单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'拍照派工单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='选片明细表') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'选片明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='看设计明细表') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'看设计明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='取件明细表') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'取件明细表', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='服务明细') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'服务明细', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='选片缩略图') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'选片缩略图', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'3', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='制作单明细') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'制作单明细', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'3', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='订单打印') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'订单打印', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'4', CAST(N'2015-05-11 15:18:52.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='摄控本总览') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'摄控本总览', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'5', CAST(N'2015-05-09 15:57:16.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='其它二销') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'其它二销', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='会员充值收款') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'会员充值收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出售清单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出售清单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租清单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租清单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购申请单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购申请单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='库存采购验收单') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'库存采购验收单', N'Brother DCP-7060D Printer', N'\\CW01\Brother DCP-7060D Printer', N'适用于(A4纸打印机)', N'2', CAST(N'2015-05-18 16:11:23.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租收款') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出售收款') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES (N'SSN001', N'礼服出售收款', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='礼服出租退押金') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'礼服出租退押金', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='新摄会收款凭据') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'新摄会收款凭据', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO if not exists (select * from [tb_ErpPrinterSet] where [ps_SingleName]='新摄会返还款凭据') begin INSERT [dbo].[tb_ErpPrinterSet] ( [ps_DividedShop], [ps_SingleName], [ps_PrinterName], [ps_PrinterPath], [ps_PrintAppliesType], [ps_SingleSort], [ps_UpdateDateTime], [ps_UpdateName]) VALUES ( N'SSN001', N'新摄会返还款凭据', N'Jolimark FP-530K+', N'\\MICROSOF-CA157D\Jolimark FP-530K+', N'适用于(针式打印机)', N'0', CAST(N'2015-06-27 09:58:30.000' AS DateTime), N'20141125111443713') end GO --2015-07-14-更新-- if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAI') <= 0 begin insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('AAAAAAI', '活动套系', '5', 'False', 'False', '', 'True', 'False') end GO if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAI') >0 begin UPDATE tb_ErpSystemCategory set Sc_ClassName='活动套系', Sc_ClassParentID='5', Sc_IsDisable='False', Sc_IsReadOnly='True', Sc_IsDelete='True' where Sc_ClassCode = 'AAAAAAI' end GO if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BFAFBCBADBDCABFDD') <= 0 begin insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('BFAFBCBADBDCABFDD', '朋友介绍', '25', 'False', 'True', '', 'True', 'False') end GO if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BFACBABGBGBJGDHIE') <= 0 begin update tb_ErpSystemCategory set Sc_IsReadOnly = 'true',Sc_IsDelete = 'true' where Sc_ClassCode = 'BFACBABGBGBJGDHIE' end GO if exists (select * from syscolumns where id=object_id('tb_ErpCustomer') and name='Cus_Type') begin ALTER TABLE tb_ErpCustomer ALTER COLUMN Cus_Type nvarchar(20) NULL; end GO update tb_ErpPackages set Pak_IntoTheBook = 0 where Pak_IntoTheBook = -1 GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_Customer_PaymentOrdersTwo') BEGIN DROP VIEW [dbo].View_Customer_PaymentOrdersTwo END GO create view View_Customer_PaymentOrdersTwo as select ID, Ord_Number, Ord_DividedShop, Ord_Type, Ord_SeriesName, Ord_SeriesPrice, Ord_Class, Ord_CustomerListID, Ord_MainContact, (select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerName1, (select Cus_Sex from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerSex1, (select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerTelephone1, (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END ) as Ord_CustomerListID2 , (select Cus_Name from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerName2, (select Cus_Telephone from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerTelephone2, (select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson, (select [Cus_NamePinyin] from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) AS name1, ((select [Cus_NamePinyin] from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber)) AS name2, (select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID, Ord_CreateDatetime ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount from tb_ErpOrder GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpPieceCommissionRecords') BEGIN DROP VIEW [dbo].View_ErpPieceCommissionRecords END GO Create view [dbo].[View_ErpPieceCommissionRecords] as SELECT tb_ErpPieceCommissionRecords.ID ,Pcr_OrderNumber ,Pcr_DigitalDivision ,Pcr_Date ,Pcr_CompletionContents ,Pcr_Quantity ,Pcr_CreateTime ,Pcr_EntryPeople ,Pcr_Type ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName ,Ord_Type ,Ord_Class ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Cus_Name ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Cus_Telephone ,Ord_SeriesName ,Ord_SeriesPrice FROM tb_ErpPieceCommissionRecords left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePaymentRecords') BEGIN DROP VIEW [dbo].View_OrdersWagePaymentRecords END GO create VIEW [dbo].[View_OrdersWagePaymentRecords] AS SELECT View_ErpPayment.ID ,Pay_OrdNumber ,Pay_AmountOf ,Pay_OpenSingle ,Pay_ThePayee ,Pay_PaymentMethod ,Pay_OrdersLocation ,Pay_ReceivableProject ,Pay_CustomNumber ,Pay_Remark ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime ,Pay_Category ,Pay_TwoPinsCategory ,Pay_UserName ,Pay_ThePayeeName ,Pay_PaymentMethodName ,Pay_TwoPinsCategoryName ,Pay_FinancialAuditdPeople ,Pay_FinancialAudit ,Pay_FinancialAuditdPeopleName ,Pay_ShootingName ,Ord_Number ,Ord_DividedShop ,Ord_Type ,Ord_Class ,Ord_CustomerName1 ,Ord_CustomerName2 ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName ,Ord_CreateDatetime ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type ,Ord_SeriesName FROM View_ErpPayment left join View_Customer_PaymentOrdersTwo on View_ErpPayment.Pay_OrdNumber=View_Customer_PaymentOrdersTwo.Ord_Number GO if not exists (select * from tb_ErpSystemCategory where sc_className='订单类别' or Sc_ClassCode='BFAGAHBFDGCABAJIH') begin insert into tb_ErpSystemCategory (Sc_ClassCode,Sc_ClassName,Sc_ClassParentID,Sc_IsDisable,Sc_IsReadOnly,Sc_IsDelete,Sc_IsEnabledURL,Sc_CreateDatetime) Values ('BFAGAHBFDGCABAJIH','订单类别','0','0',1,1,'0','2015-06-15 00:00') end GO --创建表 IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND type in (N'U')) begin --创建客户组表 CREATE TABLE [dbo].[tb_ErpCustomerGroup]( [id] [int] IDENTITY(1,1) NOT NULL, --订单号 老客户时订单号为空 [GP_OrderNumber] [nvarchar](50) not NULL, --客户关系组ID编号 [GP_CustomerGroupID] [nvarchar](50) not NULL, --客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户 [GP_GroupType] [int] not NULL, --客户类型 0 为婚纱订单客户 1 为儿童订单客户 2 写真订单客户 3 为服务套系 4 为其它订单客户 [GP_CustomerType] [int] not NULL, --客户状态 正常 意向 溜单 流失 [GP_CustomerStatus] [nvarchar](50) not NULL, --客户流失或溜单原因 少于800 字 [GP_LossReason] [nvarchar](800) not NULL, --意向程度 有点意向 很有意向 非常有意向等 [GP_DegreeOfIntent] [nvarchar](50) not NULL, --客户来源 [GP_CustomerSource] [nvarchar](50) not NULL, --介绍人CustomerID 如果为老客户转介绍来的客户时填写介绍人ID [GP_IntroducerCustomerID] [nvarchar](50) NULL, --备注说明 少于800 字 [GP_Remark] [nvarchar](800) NULL, --本组客户所属人的ID (隶属于谁的客户) 如果为空时为公共客户 [GP_BelongsPersonID] [nvarchar](50) NULL, --客户添加时间 [GP_CreateDatetime] [datetime] not NULL, --客户修改时间 [GP_UpdateDatetime] [datetime] not NULL, [GP_CreateName] [nvarchar](50) not NULL, [GP_UpdateName] [nvarchar](50) not NULL, ) --联合主键 ALTER TABLE [dbo].[tb_ErpCustomerGroup] ADD CONSTRAINT PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID PRIMARY KEY CLUSTERED ( GP_OrderNumber, GP_CustomerGroupID ) --唯一索引 CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_CustomerGroupID] ON [dbo].[tb_ErpCustomerGroup] ( [GP_CustomerGroupID] ASC ) CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup] ( [GP_OrderNumber] ASC ) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'订单号 老客户时订单号为空' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_OrderNumber' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerGroupID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组类型 0 为其它客户/订单客户 1 为老客户 2 为意向客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_GroupType' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户类型 0 为婚纱订单客户 1 为儿童订单客户 2 写真订单客户 3 为服务套系 4 为其它订单客户 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerType' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户状态 正常 意向 溜单 流失' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerStatus' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户流失或溜单原因 少于800 字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_LossReason' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'意向程度 有点意向 很有意向 非常有意向等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_DegreeOfIntent' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户来源' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CustomerSource' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'介绍人CustomerID 如果为老客户转介绍来的客户时填写介绍人ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_IntroducerCustomerID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注说明 少于800字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_Remark' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本组客户所属人的ID (隶属于谁的客户) 如果为空时为公共客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_BelongsPersonID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'添加时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_CreateDatetime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'最后修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroup', @level2type=N'COLUMN',@level2name=N'GP_UpdateDatetime' end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroupMembers]') AND type in (N'U')) begin --创建客户组成员表 CREATE TABLE [dbo].[tb_ErpCustomerGroupMembers]( [id] [int] IDENTITY(1,1) NOT NULL, --客户关系组ID编号 [GM_CustomerGroupID] [nvarchar](50) not NULL, --客户人员表中的客户编号ID [GM_CustomerID] [varchar](50) not NULL, --是否为主联系人 1 为主联系人 [GM_Master] [int] not NULL, --是否为摄影主角 1 为摄影主角 表示在本次订单中要参与拍摄的客户 [GM_ProtagonistCustomer] [int] not NULL, --相关人ID 儿童版订单客户时为宝贝ID 其它订单客户时为主联系人ID [GM_RelatedPersonID] [nvarchar](50) not NULL, --与相关人的关系 如 本人、情吕、夫妻、父子、母子、父女、母女、兄弟、姐妹、亲人和朋友等 [GM_Relation] [nvarchar](50) not NULL, --是否已成功下单 1 为已成功下单 0 为下单未成功 [GM_IsOrder] [int] not NULL, --已订单号 如果 IsOrder 为 1 填入订单号 [GM_IsOrderNumber] [nvarchar](50) NULL, ) --联合主键 ALTER TABLE [dbo].[tb_ErpCustomerGroupMembers] ADD CONSTRAINT PK_tb_ErpCustomerGroupMembers_CustomerGroupID_And_CustomerID PRIMARY KEY CLUSTERED ( GM_CustomerGroupID, GM_CustomerID ) --索引 CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroupMembers_GM_CustomerGroupID] ON [dbo].[tb_ErpCustomerGroupMembers] ( [GM_CustomerGroupID] ASC ) CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroupMembers_GM_CustomerID] ON [dbo].[tb_ErpCustomerGroupMembers] ( [GM_CustomerID] ASC ) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户组成员表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_CustomerGroupID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户人员表中的客户编号ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_CustomerID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否为主联系人 1 为主联系人 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_Master' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否为摄影主角 1 为摄影主角 表示在本次订单中要参与拍摄的客户' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_ProtagonistCustomer' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'相关人ID 儿童版订单客户时为宝贝ID 其它订单客户时为主联系人ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_RelatedPersonID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'与相关人的关系 如 本人、情吕、夫妻、父子、母子、父女、母女、兄弟、姐妹、亲人和朋友等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_Relation' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否已成功下单 1 为已成功下单 0 为下单未成功' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_IsOrder' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'已订单号 如果 IsOrder 为 1 填入订单号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomerGroupMembers', @level2type=N'COLUMN',@level2name=N'GM_IsOrderNumber' end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND type in (N'U')) begin --创建客户跟踪记录表 CREATE TABLE [dbo].[tb_ErpCustomersTrackRecord]( [id] [int] IDENTITY(1,1) NOT NULL, --跟踪的客户组ID编号 [TR_CustomerGroupID] [nvarchar](50) not NULL, --本次联系的客户人员表中的客户编号ID [TR_CustomerID] [nvarchar](50) not NULL, --本次跟踪方式 面谈、坐机电话、手机通话、邮件、短信、QQ、微信、网络留言、其它通信 [TR_TraceWay] [nvarchar](50) not NULL, --本次跟踪类型 流程按排、业务咨询、满意度调查、意向跟踪、溜单追回、关系维护、活动推广 [TR_TraceType] [nvarchar](50) not NULL, --本次沟通具体事项 如:按排拍摄时间、按排选片时间和打结婚纪念日电话等 [TR_SpecificMatters] [nvarchar](4000) not NULL, --本次沟通细节记录 如果客户返馈的信息 短信内容 QQ聊天记录等 [TR_TraceDetailedly] [nvarchar](max) not NULL, --如果是电话(一搬指通过来电精灵通话)沟通的通话录音文件路径 [TR_CallRecording] [nvarchar](500) not NULL, --少于4000字的备注说明 本次跟踪的特殊说明 [TR_Remark] [nvarchar](4000) NULL, --本次跟踪时间(为与客户沟通的开始时间) [TR_TraceDateTime] [DateTime] not NULL, --本次路踪时长(为与客户沟通所用时间 单位为分钟) 如:15 (分钟) [TR_TraceTimeLength] int not null, --本次跟踪人员ID(如门市) [TR_TracePersonID] [nvarchar](50) not NULL, --记录录入时间 [TR_CreateDateTime] [DateTime] not NULL, --记录修改时间 [TR_UpdateDateTime] [DateTime] not NULL, ) --联合主键 ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] ADD CONSTRAINT PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID PRIMARY KEY CLUSTERED ( TR_CustomerGroupID, TR_CustomerID ) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户跟踪记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'客户关系组ID编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CustomerGroupID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次联系的客户人员表中的客户编号ID' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CustomerID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪方式 面谈、坐机电话、手机通话、邮件、短信、QQ、微信、网络留言、其它通信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceWay' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪类型 流程按排、业务咨询、满意度调查、意向跟踪、溜单追回、关系维护、活动推广' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceType' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次沟通具体事项 如:按排拍摄时间、按排选片时间和打结婚纪念日电话等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_SpecificMatters' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次沟通细节记录 如果客户返馈的信息 短信内容 QQ聊天记录等' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceDetailedly' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'如果是电话(一搬指通过来电精灵通话)沟通的通话录音文件路径' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CallRecording' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'少于4000字的备注说明 本次跟踪的特殊说明' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_Remark' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪时间(为与客户沟通的开始时间)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceDateTime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次路踪时长(为与客户沟通所用时间 单位为分钟) 如:15 (分钟)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TraceTimeLength' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'本次跟踪人员ID(如门市)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_TracePersonID' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'记录录入时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_CreateDateTime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'记录修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpCustomersTrackRecord', @level2type=N'COLUMN',@level2name=N'TR_UpdateDateTime' end GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_ConvertSex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[Fun_ConvertSex] GO CREATE FUNCTION dbo.Fun_ConvertSex( @value int --性别值 ) /****** 转换性别 创建人:刘超 创建日期:2015-6-11 14:10 修改人: 修改说明: 修改日期: ******/ RETURNS nvarchar(10) AS BEGIN DECLARE @ret nvarchar(10) SET @ret = '男' if @value=0 SELECT @ret = '男' else SELECT @ret = '女' Return @ret END GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetAgeString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[Fun_GetAgeString] GO CREATE FUNCTION dbo.Fun_GetAgeString( @Birthday datetime ) /****** 根据公历生日日期计算返回年龄大小字符串 小于1岁的返回天数 创建人:刘超 创建日期:2015-6-11 14:10 修改人: 修改说明: 修改日期: ******/ RETURNS nvarchar(100) AS begin declare @ret nvarchar(100) declare @age int declare @age_day int set @age=FLOOR(datediff(day,@Birthday,getdate())/365.25) set @age_day=DATEDIFF(day, @Birthday,Getdate()) if @age < 1 set @ret =CONVERT(varchar(100), @age_day)+'天' else set @ret =CONVERT(varchar(100), @age)+'岁' return @ret end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSTemplates]') AND type in (N'U')) begin --创建短信模板表 CREATE TABLE [dbo].[tb_SMSTemplates]( [id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL, --信息发送通道 0 为短信通道发送 1 为微信通道发送 [ST_SendChannel] int not NULL, --短信模板类型 0 为人工短信 1 流程短信 2 事件短信 [ST_Type] int not NULL, --短信模板类别 0 儿童摄影客户 1 为其它摄影客户(如婚纱客户、写真客户、积分和财务短信等) [ST_Category] [int] not NULL, --短信发送事件 [ST_SendEvent] [int] not NULL, --事件值 如:X分钟的分钟数 或积分 X的积分分值 X天 X岁 X日期/时间 [ST_SendEventValue] [nvarchar](50) not NULL, --短信接收对象 AllC 所有客户 AllE所有员工 或 X手机号(最多500个手机号) [ST_ReceiveObjects] [varchar](8000) not NULL, --短信模板标题 [ST_Title] [nvarchar](200) not NULL, --短信模板内容 (建义不要超过270个字符长度) [ST_SMSContent] [nvarchar](500) not NULL, --是否启用模板 0 为禁用 1 为启用 [ST_IsEnabled] int not NULL, --备注说明 少于800 字 [ST_Remark] [nvarchar](800) NULL, --添加时间 [ST_CreateDatetime] [datetime] not NULL, --修改时间 [ST_UpdateDatetime] [datetime] not NULL ) --索引 CREATE NONCLUSTERED INDEX [IX_tb_SMSTemplates_SendEvent] ON [dbo].[tb_SMSTemplates] ( [ST_SendEvent] ASC ) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'信息发送通道 0 为短信通道发送 1 为微信通道发送' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendChannel' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类型 0 为人工短信 1 流程短信 2 事件短信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Type' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类别 0 儿童摄影客户 1 为其它摄影客户(如婚纱客户、写真客户、积分和财务短信等)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Category' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送事件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendEvent' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'事件值 如:X分钟的分钟数 或积分 X的积分分值 X天 X岁 X日期/时间 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SendEventValue' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信接收对象 AllC 所有客户 AllE所有员工 或 X手机号(最多500个手机号)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_ReceiveObjects' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板标题' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Title' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板内容 (建义不要超过270个字符长度)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_SMSContent' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'是否启用模板 0 为禁用 1 为启用 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_IsEnabled' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'备注说明 少于800 字' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_Remark' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'添加时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_CreateDatetime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'修改时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSTemplates', @level2type=N'COLUMN',@level2name=N'ST_UpdateDatetime' end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSRecords]') AND type in (N'U')) begin --创建短信发送记录表 CREATE TABLE [dbo].[tb_SMSRecords]( [id] [int] PRIMARY KEY IDENTITY(1,1) NOT NULL, --信息发送通道 0 为短信通道发送 1 为微信通道发送 [SR_SendChannel] int not NULL, --短信模板类型 0 为人工短信 1 流程短信 2 事件短信 [SR_Type] int not NULL, --短信发送事件 [SR_SendEvent] [int] not NULL, --短信生成标识 (生成短信记录时的唯一标识) 避免短信成复生成 [SR_SMSGenerateIdentity] [nvarchar](50) not NULL, --短信发送后获取服务器返回的发送短信唯一标识(用于查询短信发送情况) 短信记录在服务器上只保存1个月 [SR_SMSSendIdentity] [nvarchar](50) not NULL, --接收人手机号码,多个时用“,”号分隔 [SR_RecipientNumber] [nvarchar](4000) not NULL, --短信内容 (建义不要超过270个字符长度) [SR_Content] [nvarchar](500) not NULL, --短信预设开始发送时间 [SR_StartSendDatetime] [datetime] not NULL, --短信发送条数 [SR_SendSumCount] int not NULL, --发送状态 -1 为发送失败 0 为等待发送 1 为发送成功 2 为发送中 3 为超时短信 [SR_Status] int not NULL, --发送日志 [SR_SendLogs] [nvarchar](max) NULL, --发送报告 [SR_SendReport] [nvarchar](800) NULL, --短信生成时间 [SR_CreateDatetime] [datetime] not NULL, --短信发送时间 短信实际发送时间 [SR_SendDatetime] [datetime] NULL, --短信发送人 [SR_SMSSendSender] [nvarchar](50) not NULL, ) --创建表唯一索引 CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSGenerateIdentity] ON [dbo].[tb_SMSRecords] ( [SR_SMSGenerateIdentity] ASC ) --创建表非唯一索引 CREATE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords] ( [SR_SMSSendIdentity] ASC ) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送记录表' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'信息发送通道 0 为短信通道发送 1 为微信通道发送' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendChannel' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信模板类型 0 为人工短信 1 流程短信 2 事件短信 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Type' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送事件' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendEvent' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信生成标识 (生成短信记录时的唯一标识) 避免短信成复生成 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SMSGenerateIdentity' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送后获取服务器返回的发送短信唯一标识(用于查询短信发送情况) 短信记录在服务器上只保存1个月 ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SMSSendIdentity' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'接收人手机号码,多个时用“,”号分隔' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_RecipientNumber' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信内容 (建义不要超过270个字符长度)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Content' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信预设开始发送时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_StartSendDatetime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送条数' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendSumCount' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送状态 -1 为发送失败 0 为等待发送 1 为发送成功 2 为发送中 3 为超时短信' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_Status' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送日志' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendLogs' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'发送报告' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendReport' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信生成时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_CreateDatetime' EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'短信发送时间 短信实际发送时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_SMSRecords', @level2type=N'COLUMN',@level2name=N'SR_SendDatetime' end GO --创建表结束 if not exists (select * from syscolumns where id=object_id('tb_ErpSmsAccountInfo') and name='Smsa_SumSendCount') begin alter table tb_ErpSmsAccountInfo add Smsa_SumSendCount int NULL end GO if exists (select * from syscolumns where id=object_id('tb_SMSTemplates') and name='ST_IsEnabled') begin ALTER TABLE tb_SMSTemplates ALTER COLUMN ST_IsEnabled int not null; end GO if not exists (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SMSSendSender') begin alter table tb_SMSRecords add SR_SMSSendSender nvarchar(50) NULL end GO if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed') begin alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed' GO --类别设置中的‘服务’ 改成 ‘服务类别’ if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BEBADABBEEEGAEGFG') > 0 begin update tb_ErpSystemCategory set Sc_ClassName = '服务类别' where Sc_ClassCode = 'BEBADABBEEEGAEGFG' end GO IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_SMSRecords]') AND name = N'IX_tb_SMSRecords_SMSSendIdentity') DROP INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords] WITH ( ONLINE = OFF ) GO --创建表非唯一索引 CREATE NONCLUSTERED INDEX [IX_tb_SMSRecords_SMSSendIdentity] ON [dbo].[tb_SMSRecords] ( [SR_SMSSendIdentity] ASC ) GO if exists (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SMSSendIdentity') begin ALTER TABLE tb_SMSRecords ALTER COLUMN SR_SMSSendIdentity nvarchar(50) null; end GO if exists (select * from syscolumns where id=object_id('tb_SMSRecords') and name='SR_SendDatetime') begin ALTER TABLE tb_SMSRecords ALTER COLUMN SR_SendDatetime datetime null; end GO --2015-08-13 truncate table dbo.[tb_ErpPermissionTemplate] GO SET IDENTITY_INSERT [dbo].[tb_ErpPermissionTemplate] ON INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (1, N'StoresOPenSingle', N'门市开单', N'Print|NewOrder|ModifyOrder|OrderClsssSet|OrderClientRegionSet|OrderClientRelationSet|OrderPackagesNameSet|OrderSightsOrStageSet|OrderClientSourceSet|OrderLoveStyleSet', CAST(0x0000A485011FCE52 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012FB828 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (6, N'StoresPhotograph', N'拍照', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|PhotographClientAvatarSeeView|PhotographMicroShare|ProcessStatusReset', CAST(0x0000A4860139EC0B AS DateTime), N'20141125111443713', CAST(0x0000A4F1012BD1A9 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (7, N'StoresRepairPiece', N'初修', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|ProcessStatusReset|RepairPieceSeparatePhoto', CAST(0x0000A486013A17DD AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C1D75 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (8, N'StoresFilmSelection', N'选片', N'PhotoExport|Print|StartFilmSelection|ProcessStatusReset|FilmSelectionCache|FilmSelectionCacheManage', CAST(0x0000A486013A3D95 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C76C1 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (9, N'StoresRefinedRepair', N'精修', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|ProcessStatusReset', CAST(0x0000A486013A4984 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012C9F69 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (10, N'StoresDesign', N'设计', N'PhotoImport|PhotoExport|PhotoView|PhotoDelete|LookDesign|ProcessStatusResetDesign|ProcessStatusResetLookDesign', CAST(0x0000A486013A59A3 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CC262 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (11, N'StoresDigital', N'数码', N'AnPaiWork|SeeAnPaiWork', CAST(0x0000A486013A7B43 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D540F AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (12, N'OrderReport', N'订单报表', N'Delete|DataExport|OrderIntent', CAST(0x0000A486013AB2DB AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D6DA4 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (13, N'UserCompetence', N'员工设置权限', N'Add|Delete|Update|SeeView', CAST(0x0000A48601619A02 AS DateTime), N'20141125111443713', CAST(0x0000A48601619A01 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (14, N'DressEntry', N'礼服录入', N'Add|Delete|Update|DataExport', CAST(0x0000A4A000B8ED4B AS DateTime), N'20141125111443713', CAST(0x0000A4A500EE5934 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (15, N'DressView', N'礼服查询', N'SeeView', CAST(0x0000A4A000B8FD7F AS DateTime), N'20141125111443713', CAST(0x0000A4A000B8FD7F AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (16, N'DressManagement', N'礼服管理', N'Dress_Preselection|Dress_Rental|Dress_Valet', CAST(0x0000A4A000B90796 AS DateTime), N'20141125111443713', CAST(0x0000A4A000B90796 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (17, N'ProductCompetence', N'商品设置', N'Add|Delete|Update', CAST(0x0000A4A500E86312 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EE68C9 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (18, N'AttractionsCompetence', N'景点/次数设置', N'Add|Delete|Update', CAST(0x0000A4A500E88107 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E91A0B AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (19, N'PackagesGoodsCompetence', N'套系赠送商品设置', N'Add|Delete|Update', CAST(0x0000A4A500E8B482 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E8B482 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (20, N'SupplierCompetence', N'供应商设置', N'Add|Delete|Update', CAST(0x0000A4A500E8E4D9 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E8E4D9 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (21, N'GoodsManufacturersCompetence', N'商品厂商设置', N'Add|Delete|Update', CAST(0x0000A4A500E931A1 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E931A1 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (22, N'WageCompetence', N'工资设置', N'Add|Update', CAST(0x0000A4A500E96348 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E96348 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (23, N'RatingsProportionCompetence', N'工资提成比重设置', N'Add', CAST(0x0000A4A500E984E2 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E984E2 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (24, N'SystemCompetence', N'系统类别设置', N'Add|Delete|Update', CAST(0x0000A4A500E9BE49 AS DateTime), N'20141125111443713', CAST(0x0000A4A500E9BE49 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (25, N'CustomerSatisfactionRecordCompetence', N'客户满意度设置', N'SatisfactionSurvey|SatisfactionSurveySet', CAST(0x0000A4A500E9F63C AS DateTime), N'20141125111443713', CAST(0x0000A4D400C19672 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (26, N'CustomerCallsCompetence', N'客户来电设置', N'Delete', CAST(0x0000A4A500EA2348 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA2348 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (27, N'OutgoingCallsCompetence', N'拨出电话设置', N'Delete', CAST(0x0000A4A500EA2DB0 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA2DB0 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (28, N'MissedCallCompetence', N'未接电话设置', N'Delete', CAST(0x0000A4A500EA4466 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA4466 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (29, N'OrdersCustomerCompetence', N'订单客户设置', N'Update|DataExport', CAST(0x0000A4A500EA6500 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA70BD AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (30, N'OldCustomerCompetence', N'老客户设置', N'Add|Delete|Update|DataExport|SMSSend', CAST(0x0000A4A500EA8E8F AS DateTime), N'20141125111443713', CAST(0x0000A4A500EA8E8F AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (31, N'IntentionCustomerCompetence', N'意向客户设置', N'Add|Delete|Update|DataExport|SMSSend', CAST(0x0000A4A500EAC4D2 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EAC4D2 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (32, N'StockCompetence', N'库存查询设置', N'Add|Delete|InstockInventory|ProcurementApplication', CAST(0x0000A4A500EB3D52 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB3D52 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (33, N'ReceiptCompetence', N'入库记录设置', N'Receipt', CAST(0x0000A4A500EB6066 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB6066 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (34, N'DeliveryCompetence', N'出库记录设置', N'Delivery', CAST(0x0000A4A500EB6EA6 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB6EA6 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (35, N'PurchasingManagementCompetence', N'采购管理设置', N'PurchasingManagement|AcceptanceManagement', CAST(0x0000A4A500EB8996 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB8996 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (36, N'FixedAssetManagementCompetence', N'固定资料管理设置', N'Add|Delete|Update', CAST(0x0000A4A500EB9882 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EB9882 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (37, N'ShortSmsMessageCompetence', N'短信群发设置', N'DataExport|SMSSend', CAST(0x0000A4A500EC0D01 AS DateTime), N'20141125111443713', CAST(0x0000A4E601252F28 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (38, N'SmsSendCompetence', N'短信发送设置', N'SMSSend', CAST(0x0000A4A500EC19FB AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC19FB AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (39, N'SMSProcessCompetence', N'流程短信设置', N'SMSSend', CAST(0x0000A4A500EC2909 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC2909 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (40, N'SMSEmployeesCompetence', N'员工短信设置', N'SMSSend', CAST(0x0000A4A500EC3774 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EC3774 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (41, N'SendRecordsCompetence', N'发送记录', N'Delete|DataExport|SMSResendSend', CAST(0x0000A4A500EC4659 AS DateTime), N'20141125111443713', CAST(0x0000A4E600B790CC AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (42, N'SMSSettingsCompetence', N'短信设置', N'Add|Delete|Update', CAST(0x0000A4A500EC62D0 AS DateTime), N'20141125111443713', CAST(0x0000A4E600B76CE5 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (43, N'DayFinanceCompetence', N'日财务设置', N'DataExport|Print|FinancialAudit|FinancialExpenses', CAST(0x0000A4A500EC9037 AS DateTime), N'20141125111443713', CAST(0x0000A4BA01153D60 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (44, N'MonthFinanceCompetence', N'月财务设置', N'DataExport|Print|FinancialExpenses', CAST(0x0000A4A500EC9DA6 AS DateTime), N'20141125111443713', CAST(0x0000A4BA01154EEB AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (45, N'YearFinanceCompetence', N'年财务设置', N'DataExport|Print|FinancialExpenses', CAST(0x0000A4A500ECA76C AS DateTime), N'20141125111443713', CAST(0x0000A4BA01155CD1 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (46, N'CostingCompetence', N'成本核算设置', N'DataExport', CAST(0x0000A4A500ECB2C8 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ECB2C8 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (47, N'StatisticalInquiryAllWagesCompetence', N'工资管理设置', N'ViewAll', CAST(0x0000A4A500ECC2EA AS DateTime), N'20141125111443713', CAST(0x0000A4F800A354C7 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (48, N'TwoSalesOrderCompetence', N'其它消费设置', N'Add|Delete|Update|SMSSend|OtherConsumerReceivables', CAST(0x0000A4A500ED3D56 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED3D56 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (49, N'CashExpendituresCompetence', N'现金支出设置', N'Add|Delete|Update|Print|ReportForm', CAST(0x0000A4A500ED6136 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED6136 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (50, N'OtherIncomeCompetence', N'其它收入设置', N'Add|Delete|Print', CAST(0x0000A4A500ED738F AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED738F AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (51, N'PieceCommissionRecordsCompetence', N'计件提成设置', N'Add|Delete', CAST(0x0000A4A500ED9612 AS DateTime), N'20141125111443713', CAST(0x0000A4A500ED9612 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (52, N'StaffAwardPunishCompetence', N'员工奖罚设置', N'Add|Delete|Update', CAST(0x0000A4A500EDA5E5 AS DateTime), N'20141125111443713', CAST(0x0000A4A500EDA5E5 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (53, N'OrdersReceivablesCompetence', N'订单收款设置', N'Delete|OrdersReceivables|UpdatePaymentTime|OrdersLatePayment|OrdersLatePickGoods|OrderPaymentMethodSet', CAST(0x0000A4A500EDBA19 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012FA04F AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (54, N'BulletinBoardCompetence', N'公告栏', N'Delete|Update|Announcement', CAST(0x0000A4A500EDE073 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B1A80 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (55, N'StoresPhotosPrints', N'相片冲印', N'Delete|PhotosPrints|OrderSendOut|OrderRework|OrderComplete', CAST(0x0000A4A600B7DAB6 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CFDBD AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (56, N'StoresTotakePiece', N'发片取件', N'DataExport|TotakePiece|OrderSendOut|OrderRework|OrderComplete|OrderPickup|TotakePieceMonthRework|TotakePieceSentNotBack', CAST(0x0000A4A600B7F555 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012D22CF AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (57, N'MemberManage', N'会员管理', N'Delete|DataImport|DataExport|Print|SMSSend|Member_Recharge|Member_Cash|Member_PointsRedeem|Member_TurnPoints|Member_Logout|Member_ChangingCard|Member_SendPoint|Member_PasswordSet|Member_SendViceCard|Member_OpenCard|Member_CashBackCash|Member_GradeUpdateType|Member_ServiceData|Member_PhotographerOpenCard|Member_PhotographerReturnAmount|Member_PhotographerUseGift|Member_ServiceKoufei|Member_ParameterSet_BaseSet|Member_ParameterSet_PointsSet|Member_ParameterSet_CashBackProportionSet|Member_ParameterSet_RechargeTypeSet|Member_ParameterSet_GradeSet|Member_ParameterSet_ServiceContentSet|Member_ParameterSet_PackageServiceSet|Member_ParameterSet_PhotographerConferenceSet|Member_ViceCardReclaim', CAST(0x0000A4A600B830A7 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012E799C AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (58, N'PhotoStudioInfo', N'本店信息设置', N'Update', CAST(0x0000A4A600EE9711 AS DateTime), N'20141125111443713', CAST(0x0000A4A600EE9711 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (59, N'PrinterSetup', N'打印机设置', N'Update', CAST(0x0000A4A600EEA53A AS DateTime), N'20141125111443713', CAST(0x0000A4A600EEA53A AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (60, N'Attendance', N'考勤管理', N'AttendanceSigning|AttendanceDataManager', CAST(0x0000A4A800DBFAEF AS DateTime), N'20141125111443713', CAST(0x0000A4A800DBFAEF AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (61, N'FinancialExpensesCompetence', N'财务支出设置', N'Add|Delete|Update|Print|ReportForm', CAST(0x0000A4B900E2B3BF AS DateTime), N'20141125111443713', CAST(0x0000A4B900E2B3BF AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (62, N'SystemRightsManagement', N'权限管理', N'AddRole|DelRole|SetUserRole|SetUserExclusiveCompetence', CAST(0x0000A4C000E29B8C AS DateTime), N'20141125111443713', CAST(0x0000A4C000E29B8C AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (63, N'GroupInfo', N'集团信息', N'SeeView', CAST(0x0000A4F1012B3AF1 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012B3AF1 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (64, N'StoresKePan', N'刻盘', N'KePanCD|KePanUDisk', CAST(0x0000A4F1012CD5B4 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012CD5B4 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (65, N'CameraControlBook', N'摄控本', N'Print|SMSSend|CameraControlBook_PhotographClientAnPai|CameraControlBook_FilmsSelectionClientAnPai|CameraControlBook_LookDesignClientAnPai|CameraControlBook_TakePiecesClientAnPai|CameraControlBook_ServiceClientAnPai|CameraControlBook_SelectDressClientAnPai|CameraControlBook_AnPaiQuantitySet|CameraControlBook_SelectDress', CAST(0x0000A4F1012E3227 AS DateTime), N'20141125111443713', CAST(0x0000A4F1012E3227 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (66, N'TasksAssigned', N'任务交办', N'Add|Delete|Update', CAST(0x0000A4F2009B76C5 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B76C5 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (67, N'MattersApplication', N'事项申请', N'Add|Delete|Update|Audit', CAST(0x0000A4F2009B8CE6 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009B8CE6 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (68, N'CommunicationAide', N'沟通助手', N'Add|Delete|AudioPlayback', CAST(0x0000A4F2009BC74E AS DateTime), N'20141125111443713', CAST(0x0000A4F2009C5810 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (69, N'MyCallCenter', N'通话中心', N'AudioPlayback', CAST(0x0000A4F2009C6884 AS DateTime), N'20141125111443713', CAST(0x0000A4F2009C6884 AS DateTime), N'20141125111443713') INSERT [dbo].[tb_ErpPermissionTemplate] ([ID], [Pte_TemplateMark], [Pte_TemplateName], [Pte_PermissionValue], [Pte_CreateDatetime], [Pte_CreateName], [Pte_UpdateDatetime], [Pte_UpdateName]) VALUES (70, N'SatisticalInquiryEmployeesCompetence', N'统计员工资料', N'ViewAll', CAST(0x0000A4F800A5FA3B AS DateTime), N'20141125111443713', CAST(0x0000A4F800A5FA3B AS DateTime), N'20141125111443713') SET IDENTITY_INSERT [dbo].[tb_ErpPermissionTemplate] OFF GO IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID') ALTER TABLE [dbo].[tb_ErpCustomerGroup] DROP CONSTRAINT [PK_tb_ErpCustomerGroup_OrderNumber_And_CustomerGroupID] GO --设置主键 IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'PK_tb_ErpCustomerGroup_CustomerGroupID') ALTER TABLE [dbo].[tb_ErpCustomerGroup] ADD CONSTRAINT PK_tb_ErpCustomerGroup_CustomerGroupID PRIMARY KEY CLUSTERED ( GP_CustomerGroupID ) GO IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'IX_tb_ErpCustomerGroup_OrderNumber') DROP INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup] WITH ( ONLINE = OFF ) GO IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomerGroup]') AND name = N'IX_tb_ErpCustomerGroup_OrderNumber') CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomerGroup_OrderNumber] ON [dbo].[tb_ErpCustomerGroup] ( [GP_OrderNumber] ASC ) GO IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomer]') AND name = N'IX_tb_ErpOrderNumberRecord_Cus_CustomerNumber') CREATE UNIQUE NONCLUSTERED INDEX [IX_tb_ErpOrderNumberRecord_Cus_CustomerNumber] ON [dbo].[tb_ErpCustomer] ( [Cus_CustomerNumber] ASC ) GO --打印设置 分辨率名称 if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionName') begin alter table tb_ErpPrinterSet add ps_ResolutionName nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionName')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionName' GO --打印设置 分辨率X if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionX') begin alter table tb_ErpPrinterSet add ps_ResolutionX nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionX')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率X' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionX' GO --打印设置 分辨率名称Y if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionY') begin alter table tb_ErpPrinterSet add ps_ResolutionY nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionY')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称Y' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionY' GO --打印设置 打印进纸设置 if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed') begin alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed' GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_ConvertDate]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[fn_ConvertDate] GO CREATE function [dbo].[fn_ConvertDate](@date datetime) /****** --转换日期如果日小于等于1900-01-01 返回null 创建人:刘工 创建日期:2015-7-30 修改人: 修改说明: 修改日期: ******/ Returns datetime As Begin Declare @ReturnDate datetime if(@date>'1900-01-01') set @ReturnDate=@date Return @ReturnDate End GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'*','x') WHERE [Prod_Number] like '%*%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'?','_') WHERE [Prod_Number] like '%?%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],':','_') WHERE [Prod_Number] like '%:%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'|','_') WHERE [Prod_Number] like '%|%' GO UPDATE [dbo].[tb_ErpOrderProductList] SET [OPlist_ProdName] = Replace([OPlist_ProdName],'*','x') WHERE [OPlist_ProdName] like '%*%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'?','_') WHERE [Prod_Number] like '%?%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],':','_') WHERE [Prod_Number] like '%:%' GO UPDATE [dbo].[tb_ErpProduct] SET [Prod_Number] = Replace([Prod_Number],'|','_') WHERE [Prod_Number] like '%|%' GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_ReservationPhotographyTime]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[fn_ReservationPhotographyTime] GO CREATE function [dbo].[fn_ReservationPhotographyTime](@CreateDateTime datetime,@ReservationTime datetime, @ordtype char(1)) /****** --获取预约拍照时间 如果是成长套系时返回开单时按排的预计拍照时间 --如果不是成长套系时返回的是开单时间 创建人:刘工 创建日期:2015-7-30 修改人: 修改说明: 修改日期: ******/ Returns datetime As Begin Declare @ReturnDate datetime set @ReturnDate=@CreateDateTime if(@ordtype='1' and len(@ReservationTime)>=10) set @ReturnDate=@ReservationTime Return @ReturnDate End GO --摄影视图 记录拍摄状态 拍摄时间 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_PhotographyView]')) DROP VIEW [dbo].[Vw_PhotographyView] GO CREATE VIEW [dbo].[Vw_PhotographyView] AS select max(Ordpg_Number) as Ordpg_Number, Ordpg_ViceNumber, max(Ordpg_PhotographyTime) as Ordpg_PhotographyTime, --拍摄状态 0:未拍 Ordpg_PhotographyStatus=Ordpg_PhotographyCount: OK(已拍) 否则:拍照中 sum(CONVERT(int,Ordpg_PhotographyStatus)) as Ordpg_PhotographyStatus, Count(Ordpg_PhotographyStatus) as Ordpg_PhotographyCount from tb_ErpOrdersPhotography group by Ordpg_ViceNumber GO --订单商品取件状态视图 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProductPickupView]')) DROP VIEW [dbo].[Vw_OrderProductPickupView] GO CREATE VIEW [dbo].[Vw_OrderProductPickupView] AS select max(OPlist_OrderNumber) as OPlist_OrderNumber, OPlist_ViceNumber, sum(CONVERT(int,[OPlist_PickupStatus])) as OPlist_PickupStatus, max(OPlist_PickupTime) as OPlist_PickupTime, sum(CONVERT(int,OPlist_CompletedStatus)) as OPlist_CompletedStatus, max(OPlist_CompletedTime) as OPlist_CompletedTime, count(id) productCount from [tb_ErpOrderProductList] where OPlist_Type ='2' group by OPlist_ViceNumber GO --订单流程客户 只显示未取件的客户 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProcessCustomer]')) DROP VIEW [dbo].[Vw_OrderProcessCustomer] GO CREATE VIEW [dbo].[Vw_OrderProcessCustomer] AS --订单流程客户 只显示未取件的客户 SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_Class,CONVERT(int,Ord_Type) as Ord_Type, Ord_OrderClass, CASE Ord_SinceOrderNumber WHEN '' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, [Age_String] AS 年龄, [Age_Day] AS 天, [Age_Year] AS 年, dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别, dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人, --dbo.fn_ChineseToSpell((select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,''))) as 接单人拼音, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_PhotographyView].Ordpg_PhotographyTime)) AS 拍摄时间, (case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) =0 then '未拍' else case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) = isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1) then 'OK' else '拍照中' end end) AS 拍照状态, isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,0) as Ordpg_PhotographyCount, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计时间, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修时间, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计时间, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) =0 then '未取' else case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分取件' end end) AS 取件状态, isnull([dbo].[Vw_OrderProductPickupView].productCount,0) as productCount, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_PickupTime)) AS 取件日期, (case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) =0 then '未完' else case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分完件' end end) AS 齐件状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_CompletedTime)) AS 齐件日期, dbo.fn_ReservationPhotographyTime(Ord_CreateDateTime,(select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime DESC),Ord_Type) AS 预约日期 ,Ord_CreateDateTime FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join [dbo].[Vw_PhotographyView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_PhotographyView].Ordpg_ViceNumber left join [dbo].[Vw_OrderProductPickupView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_OrderProductPickupView].OPlist_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber where CONVERT(int,Ord_Type) < 3 and( isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1) <> isnull([dbo].[Vw_OrderProductPickupView].productCount,1) or isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1) <> isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1)) GO --订单流程客户 显示已取件和未取件的所有客户 数据效多查询时较慢 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderProcessCustomerAll]')) DROP VIEW [dbo].[Vw_OrderProcessCustomerAll] GO CREATE VIEW [dbo].[Vw_OrderProcessCustomerAll] AS --订单流程客户 显示已取件和未取件的所有客户 数据效多查询时较慢 SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_Class,CONVERT(int,Ord_Type) as Ord_Type, Ord_OrderClass, CASE Ord_SinceOrderNumber WHEN '' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, [Age_String] AS 年龄, [Age_Day] AS 天, [Age_Year] AS 年, dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别, dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (select stuff((select ',' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,'')) as 接单人, --dbo.fn_ChineseToSpell((select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('')),1,1,''))) as 接单人拼音, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_PhotographyView].Ordpg_PhotographyTime)) AS 拍摄时间, (case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) =0 then '未拍' else case when (isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyStatus,1)) = isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,1) then 'OK' else '拍照中' end end) AS 拍照状态, isnull([dbo].[Vw_PhotographyView].Ordpg_PhotographyCount,0) as Ordpg_PhotographyCount, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计时间, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修时间, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计时间, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) =0 then '未取' else case when (isnull([dbo].[Vw_OrderProductPickupView].[OPlist_PickupStatus],1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分取件' end end) AS 取件状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_PickupTime)) AS 取件日期, isnull([dbo].[Vw_OrderProductPickupView].productCount,0) as productCount, (case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) =0 then '未完' else case when (isnull([dbo].[Vw_OrderProductPickupView].OPlist_CompletedStatus,1)) = isnull([dbo].[Vw_OrderProductPickupView].productCount,1) then 'OK' else '部分完件' end end) AS 齐件状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime([dbo].[Vw_OrderProductPickupView].OPlist_CompletedTime)) AS 齐件日期, dbo.fn_ReservationPhotographyTime(Ord_CreateDateTime,(select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime DESC),Ord_Type) AS 预约日期 ,Ord_CreateDateTime FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join [dbo].[Vw_PhotographyView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_PhotographyView].Ordpg_ViceNumber left join [dbo].[Vw_OrderProductPickupView] on dbo.tb_ErpOrderDigital.Ordv_ViceNumber=[dbo].[Vw_OrderProductPickupView].OPlist_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber where CONVERT(int,Ord_Type) < 3 GO --查询员工生日视图 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_MemorialDayEmployeeList]')) DROP VIEW [dbo].[Vw_MemorialDayEmployeeList] GO CREATE VIEW [Vw_MemorialDayEmployeeList] AS SELECT [ID] ,[User_Name] ,[User_Sex] ,[User_Telephone] ,User_DateOfBirth ,dbo.Fun_GetGregorianCalendarNowYearBirthday([User_DateOfBirth],[User_BirthdayLunar]) as GregorianCalendar_NowYearBirthday FROM [dbo].[tb_ErpUser] where User_Status='在职' and len(User_DateOfBirth)>=10 and len(User_DateOfBirth)>=10 and len(User_Telephone)>=11 GO IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID') ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] DROP CONSTRAINT [PK_tb_ErpCustomersTrackRecord_CustomerGroupID_And_CustomerID] GO --设置主键 IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'PK_tb_ErpCustomersTrackRecord_id') begin ALTER TABLE [dbo].[tb_ErpCustomersTrackRecord] ADD CONSTRAINT PK_tb_ErpCustomersTrackRecord_id PRIMARY KEY CLUSTERED ( id ) end GO --索引 IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'IX_tb_ErpCustomersTrackRecord_CustomerGroupID') begin CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomersTrackRecord_CustomerGroupID] ON [dbo].[tb_ErpCustomersTrackRecord] ( [TR_CustomerGroupID] ASC ) end GO --索引 IF not EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND name = N'IX_tb_ErpCustomersTrackRecord_CustomerID') begin CREATE NONCLUSTERED INDEX [IX_tb_ErpCustomersTrackRecord_CustomerID] ON [dbo].[tb_ErpCustomersTrackRecord] ( [TR_CustomerID] ASC ) end GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetGregorianCalendarNowYearBirthday]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[Fun_GetGregorianCalendarNowYearBirthday] GO CREATE FUNCTION [dbo].[Fun_GetGregorianCalendarNowYearBirthday]( @Birthday varchar(100), @BirthdayLunar nvarchar(10)--, --是否为农历日期 0 为公历直接原日期返回 1 为农历将转为公历日期 2 为农历闰月将转为对闰月对应的公历日期 ) /****** 根据生日获取当前年的公历生日日期 创建人:刘超 创建日期:2015-6-11 14:10 修改人: 修改说明: 修改日期: ******/ RETURNS datetime AS begin declare @retdates datetime declare @isLeapMonth bit set @isLeapMonth=0 declare @month varchar(3) declare @day varchar(3) declare @now datetime if CONVERT(int, left(@Birthday,4))>1900 begin if len(@Birthday)>=8 begin set @month=Month(Replace(Replace(@Birthday,'-29','-28'),'-30','-28')) set @day =Replace(Right(@Birthday,2),'-','') set @now=Getdate() if @BirthdayLunar='2' set @isLeapMonth=1 if @BirthdayLunar='0' set @retdates=CONVERT(varchar(100),YEAR(@now))+'-'+@month+'-'+@day else set @retdates= dbo.GetCalender(@month,@day,@now,@isLeapMonth) end end return CONVERT(varchar(100), @retdates, 20) end GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_GetGregorianCalendar]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[Fun_GetGregorianCalendar] GO CREATE FUNCTION [dbo].[Fun_GetGregorianCalendar]( @Birthday varchar(100), @BirthdayLunar nvarchar(10)--, --是否为农历日期 0 为公历直接原日期返回 1 为农历将转为公历日期 2 为农历闰月将转为对闰月对应的公历日期 ) /****** 转农历为公历 获取公历生日日期 创建人:刘超 创建日期:2015-6-11 14:10 修改人: 修改说明: 修改日期: ******/ RETURNS datetime AS begin declare @retdates datetime declare @isLeapMonth bit if CONVERT(int, left(@Birthday,4))>1900 begin if len(@Birthday)>=8 begin set @isLeapMonth=0 if @BirthdayLunar='2' set @isLeapMonth=1 if @BirthdayLunar='0' set @retdates=@Birthday else set @retdates= dbo.GetCalender(Month(Replace(Replace(@Birthday,'-29','-28'),'-30','-28')),Replace(Right(@Birthday,2),'-',''),Left(@Birthday,4),@isLeapMonth) end end return CONVERT(varchar(100), @retdates, 20) end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_Version]') AND type in (N'U')) begin --软件版本表 CREATE TABLE [dbo].[tb_Version]( [id] [int] IDENTITY(1,1) NOT NULL, --版本号 [TV_Version] [nvarchar](50) not NULL, --控制命 [TV_ControlCommand] [nvarchar](50) NULL, [TV_ValidDateRun] [datetime] NULL, [TV_CreateDatetime] [datetime] not NULL, [TV_UpdateDatetime] [datetime] not NULL, ) end GO --在选片日志表中添加选片信息字段 if not exists (select * from syscolumns where id=object_id('tb_ErpOrderProductLOG') and name='Ordplg_SelectionFilmInfo') begin alter table tb_ErpOrderProductLOG add [Ordplg_SelectionFilmInfo] nvarchar(max) NULL end GO IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_UserInfo]')) DROP VIEW [dbo].[View_UserInfo] GO CREATE VIEW [dbo].[View_UserInfo] AS SELECT User_Account as Account, User_Password as PWD, User_EmployeeID AS UserID, [User_Name] AS UserName, User_Status as dimission, User_Sex AS Sex, User_FirstFingerprintID AS loginnoID1, User_SecondaryFingerprintID AS loginnoID2, 0 as [level] FROM dbo.tb_ErpUser GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomerAll]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll] GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: 刘超 -- Create date: 2015-08-09 -- Description: 更新聚合客户表中所有客户 -- ============================================= CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomerAll] ( @ReturnI int output --返回更新记录数 ) AS BEGIN truncate table [dbo].[tempTB_AggregationCustomer] insert into [tempTB_AggregationCustomer] select * from [Vw_AggregationCustomer] truncate table [dbo].[tempTB_GroupByAggregationCustomer] insert into [tempTB_GroupByAggregationCustomer] select * from [Vw_GroupByAggregationCustomer] set @ReturnI=(select count(*) from [tempTB_AggregationCustomer]) ----- END GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpCustomersTrackRecord]') AND type in (N'U')) DROP TABLE [dbo].[tb_ErpCustomersTrackRecord] GO --------2015-08-13--更新---- IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vwp_GetLastClientTrackRecord') BEGIN DROP VIEW [dbo].Vwp_GetLastClientTrackRecord END GO CREATE TABLE [dbo].[tb_ErpCustomersTrackRecord]( [id] [int] IDENTITY(1,1) NOT NULL, [TR_CustomerGroupID] [nvarchar](50) NULL, [TR_CustomerID] [nvarchar](50) NULL, [TR_TraceWay] [nvarchar](50) NULL, [TR_TraceType] [nvarchar](50) NULL, [TR_SpecificMatters] [nvarchar](4000) NULL, [TR_Communicationstatus] [nvarchar](50) NULL, [TR_TraceDetailedly] [nvarchar](max) NULL, [TR_CallRecording] [nvarchar](500) NULL, [TR_Remark] [nvarchar](4000) NULL, [TR_TraceDateTime] [datetime] NULL, [TR_TraceTimeLength] [int] NULL, [TR_TracePersonID] [nvarchar](50) NULL, [TR_CreateDateTime] [datetime] NULL, [TR_UpdateDateName] [nvarchar](50) NULL, CONSTRAINT [PK_tb_ErpCustomersTrackRecord_id] 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] GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vwp_GetLastClientTrackRecord]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[Vwp_GetLastClientTrackRecord] AS SELECT id, TR_CustomerGroupID, TR_CustomerID, TR_TraceWay, TR_TraceType, TR_SpecificMatters, TR_Communicationstatus, TR_TraceDetailedly, TR_CallRecording, TR_Remark, TR_TraceDateTime, TR_TraceTimeLength, TR_TracePersonID, TR_CreateDateTime, TR_UpdateDateName FROM dbo.tb_ErpCustomersTrackRecord WHERE (id IN (SELECT MAX(id) AS Expr1 FROM dbo.tb_ErpCustomersTrackRecord AS tb_ErpCustomersTrackRecord_1 GROUP BY TR_CustomerGroupID)) ' GO -------------------2015-08-04------------------------ if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'AAAAAAJ') <= 0 begin insert into tb_ErpSystemCategory(Sc_ClassCode, Sc_ClassName, Sc_ClassParentID, Sc_IsDisable, Sc_IsReadOnly, Sc_URL, Sc_IsDelete, Sc_IsEnabledURL) values('AAAAAAJ', '沟通情况', '0', 'False', 'True', '', 'True', 'False') end --添加函数(客户意向类型) if exists(select 1 from sysobjects where id=object_id('fn_CheckClientIntentType') and objectproperty(id,'IsInlineFunction')=0) begin drop function fn_CheckClientIntentType end GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_CheckClientIntentType]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN execute dbo.sp_executesql @statement = N'--客户意向类型 CREATE function [dbo].[fn_CheckClientIntentType](@FID varchar(800)) /****** 分类字符转换 创建人:滕工 创建日期:2014-6-23 14:55:29 修改人: 修改说明: 修改日期: ******/ Returns varchar(800) As Begin Declare @ReturnName varchar(1000) set @ReturnName = '''' if @FID = ''0'' begin set @ReturnName = ''婚纱意向'' end else if @FID = ''1'' begin set @ReturnName = ''儿童意向'' end else if @FID = ''2'' begin set @ReturnName = ''写真意向'' end else if @FID = ''3'' begin set @ReturnName = ''服务意向'' end else if @FID = ''4'' begin set @ReturnName = ''其他意向'' end Return @ReturnName End ' END GO -------------------2015-07-28------------------------ --影楼字段长度 if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_ReservationExplanation') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_ReservationExplanation nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_SingleExplanation') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_SingleExplanation nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_SingleTitle') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_SingleTitle nvarchar(500) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_ProductionNotes') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_ProductionNotes nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_DressDescription') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_DressDescription nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_About') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_About nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_PhotoThumbnail') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_PhotoThumbnail nvarchar(2000) end if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_PhotoAlbum') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_PhotoAlbum nvarchar(2000) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_URL') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_URL nvarchar(200) end GO if exists (select * from syscolumns where id=object_id('tb_ErpCompanyInfo') and name='Company_Address') begin ALTER TABLE tb_ErpCompanyInfo ALTER COLUMN Company_Address nvarchar(200) end GO -------------------2015-07-28------------------------ --打印设置 分辨率名称 if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionName') begin alter table tb_ErpPrinterSet add ps_ResolutionName nvarchar(2) NULL end GO IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionName')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionName' GO --打印设置 分辨率X if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionX') begin alter table tb_ErpPrinterSet add ps_ResolutionX nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionX')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率X' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionX' GO --打印设置 分辨率名称Y if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_ResolutionY') begin alter table tb_ErpPrinterSet add ps_ResolutionY nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_ResolutionY')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'分辨率名称Y' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_ResolutionY' GO -------------------2015-07-23------------------------ --打印设置 打印进纸设置 if not exists (select * from syscolumns where id=object_id('tb_ErpPrinterSet') and name='ps_PaperFeed') begin alter table tb_ErpPrinterSet add ps_PaperFeed nvarchar(2) NULL end IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'MS_Description' , N'SCHEMA',N'dbo', N'TABLE',N'tb_ErpPrinterSet', N'COLUMN',N'ps_PaperFeed')) EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'打印机进纸方向设置 0:前进纸 1:后进纸' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_ErpPrinterSet', @level2type=N'COLUMN',@level2name=N'ps_PaperFeed' GO --类别设置中的‘服务’ 改成 ‘服务类别’ if (select count(ID) from tb_ErpSystemCategory where Sc_ClassCode = 'BEBADABBEEEGAEGFG') > 0 begin update tb_ErpSystemCategory set Sc_ClassName = '服务类别' where Sc_ClassCode = 'BEBADABBEEEGAEGFG' end GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberCard') BEGIN DROP VIEW [dbo].BView_MemberCard END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberCard]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MemberCard] AS SELECT dbo.tb_ErpCustomer.ID AS Cus_ID, dbo.tb_ErpCustomer.Cus_CustomerNumber, dbo.tb_ErpCustomer.Cus_Type, dbo.tb_ErpCustomer.Cus_Name, dbo.tb_ErpCustomer.Cus_Sex, dbo.tb_ErpCustomer.Cus_Birthday, dbo.tb_ErpCustomer.Cus_BirthdayLunar, dbo.tb_ErpCustomer.Cus_Relations, dbo.tb_ErpCustomer.Cus_QQ, dbo.tb_ErpCustomer.Cus_MicroSignal, dbo.tb_ErpCustomer.Cus_Telephone, dbo.tb_ErpCustomer.Cus_FixedPhone, dbo.tb_ErpCustomer.Cus_Region, dbo.tb_ErpCustomer.Cus_Address, dbo.tb_ErpCustomer.Cus_WorkUnit, dbo.tb_ErpCustomer.Cus_BabyWeight, dbo.tb_ErpCustomer.Cus_BornHospital, dbo.tb_ErpCustomer.Cus_Zodiac, dbo.tb_ErpCustomer.Cus_DayForMarriage, dbo.tb_ErpCustomer.Cus_DayForMarriageLunar, dbo.tb_ErpCustomer.Cus_CustomerSource, dbo.tb_ErpCustomer.Cus_Status, dbo.tb_ErpCustomer.Cus_LossReason, dbo.tb_ErpCustomer.Cus_ServiceType, dbo.tb_ErpCustomer.Cus_Remark, dbo.tb_ErpCustomer.Cus_CreateName, dbo.tb_ErpCustomer.Cus_CreateDateTime, dbo.tb_ErpCustomer.Cus_UpdateName, dbo.tb_ErpCustomer.Cus_UpdateDateTime, dbo.tb_ErpCustomer.Cus_CustomizeNumber, dbo.tb_ErpCustomer.Cus_DegreeOfIntent, dbo.tb_ErpMemberCard.ID, dbo.tb_ErpMemberCard.Mc_Number, dbo.tb_ErpMemberCard.Mc_CradNumber, dbo.tb_ErpMemberCard.Mc_CustomerNumber, dbo.tb_ErpMemberCard.Mc_CardType, dbo.tb_ErpMemberCard.Mc_Money, dbo.tb_ErpMemberCard.Mc_TraderPassword, dbo.tb_ErpMemberCard.Mc_UsedNumber, dbo.tb_ErpMemberCard.Mc_Status, dbo.tb_ErpMemberCard.Mc_Remark, dbo.tb_ErpMemberCard.Mc_CreateDatetime, dbo.tb_ErpMemberCard.Mc_CreateName, dbo.tb_ErpMemberCard.Mc_UpdateDateTime, dbo.tb_ErpMemberCard.Mc_UpdateName FROM dbo.tb_ErpCustomer RIGHT OUTER JOIN dbo.tb_ErpMemberCard ON dbo.tb_ErpCustomer.Cus_CustomerNumber = dbo.tb_ErpMemberCard.Mc_CustomerNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MemberMain_GoldMember') BEGIN DROP VIEW [dbo].BView_MemberMain_GoldMember END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MemberMain_GoldMember]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MemberMain_GoldMember] AS SELECT Cus_ID, ID AS Mc_ID, Mc_Status, Mc_Number, Mc_CradNumber AS 会员卡号, Cus_Name AS 姓名, dbo.fn_CheckSex(Cus_Sex) AS 性别, Cus_Telephone AS 电话, Mc_CardType AS 类型, dbo.fn_GetMember(Mc_Number, 1) AS 积分, Mc_Money AS 金额, dbo.fn_GetMember(Mc_Number, 2) AS 折扣, dbo.fn_GetMember(Mc_Number, 3) AS 套系金额, dbo.fn_GetMember(Mc_Number, 4) AS 已返金额, dbo.fn_GetMember(Mc_Number, 5) AS 已取出金额, (SELECT COUNT(Mcse_ServiceCount) AS Expr1 FROM dbo.tb_ErpMemberCardServiceContent WHERE (Mcse_Number = dbo.BView_MemberCard.Mc_Number)) AS 服务次数, (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''积分副卡'')) AS 积分副卡, (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_2 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''现金副卡'')) AS 现金副卡, (SELECT COUNT(Mvc_Number) AS Expr1 FROM dbo.tb_ErpMemberCardViceCard AS tb_ErpMemberViceCard_1 WHERE (Mvc_Number = dbo.BView_MemberCard.Mc_Number) AND (Mvc_Status = ''1'') AND (Mvc_ViceCardType = ''返现副卡'')) AS 返现副卡, Mc_Remark AS 备注, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Mc_CreateDatetime)) AS 办卡日期 FROM dbo.BView_MemberCard WHERE (Mc_Status = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotFilmSelection') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotFilmSelection END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotFilmSelection] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 录入, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 录入时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotLookDesign') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotLookDesign END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotLookDesign] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 录入者, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime) AS 录入时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPhotographed') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPhotographed END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPhotographed] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrdersPhotography.ID AS PID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrder.Ord_CreateDateTime)) AS 订单日期, dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称, dbo.fn_CheckPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态, dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime) AS 摄影时间, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师, dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 备注, (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotPickup') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotPickup END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotPickup]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotPickup] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, tb_ErpOrderProductList.ID AS PPID, OPlist_ProdName AS 商品名称, dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 取件状态, dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件日期, OPlist_ReservationTakeName AS 取件人, dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 加急日期 ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotSelectDress') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotSelectDress END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotSelectDress] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime) AS 选礼服时间, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime) AS 安排时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookDeputyStatisticNotWedding') BEGIN DROP VIEW [dbo].BView_CameraControlBookDeputyStatisticNotWedding END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookDeputyStatisticNotWedding]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookDeputyStatisticNotWedding] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpWeddingService.ID AS WID, Ord_Type, dbo.tb_ErpOrder.Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.tb_ErpWeddingService.Ws_ProdName AS 婚庆内容, dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态, dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDate) AS 婚庆日期, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2, dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注, (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainFilmSelection') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainFilmSelection END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainFilmSelection]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainFilmSelection] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName) AS 选片师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间, dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 选片时间查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatcher) AS 安排人, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionDispatchTime)) AS 安排时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainFilmSelection_DetailPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainFilmSelection_DetailPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainFilmSelection_DetailPrint]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainFilmSelection_DetailPrint] AS SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName AS 选片师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_Birthday') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainLately_Birthday END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_Birthday]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainLately_Birthday] AS SELECT ID, Cus_Name AS 姓名, dbo.fn_CheckSex(Cus_Sex) AS 性别, Cus_Telephone AS 电话, Cus_Birthday AS 生日, case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_BirthdayLunar) end AS 是否农历, Cus_Type AS 客户类型 FROM dbo.tb_ErpCustomer WHERE (Cus_Birthday IS NOT NULL and Cus_Birthday != '''') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_GetMarried') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainLately_GetMarried END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_GetMarried]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainLately_GetMarried] AS SELECT ID, Cus_Name AS 姓名, dbo.fn_CheckSex(Cus_Sex) AS 性别, Cus_DayForMarriage AS 婚期, case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_DayForMarriageLunar) end AS 是否农历, Cus_Type AS 客户类型, Cus_Telephone AS 电话 FROM dbo.tb_ErpCustomer WHERE (Cus_DayForMarriage IS NOT NULL) AND (Cus_DayForMarriage !='''') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLately_MarryAnniversary') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainLately_MarryAnniversary END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLately_MarryAnniversary]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainLately_MarryAnniversary] AS SELECT ID, Cus_Name AS 姓名, dbo.fn_CheckSex(Cus_Sex) AS 性别, Cus_Telephone AS 电话, Cus_Type AS 客户类型, Cus_DayForMarriage AS 婚期, case when Cus_Birthday = '''' then '''' else dbo.fn_CheckLunar(Cus_DayForMarriageLunar) end AS 是否农历 FROM dbo.tb_ErpCustomer WHERE (Cus_DayForMarriage != '''' and Cus_DayForMarriage is not null) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLookDesign') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainLookDesign END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLookDesign]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainLookDesign] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName) AS 看设计师, dbo.fn_CheckDateTime(Ordv_ReservationLookDesignTime) AS 看设计时间, Ordv_ReservationLookDesignTime AS 看设计时间查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatcher) AS 安排人, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignDispatchTime)) AS 安排时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainLookDesign_DetailPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainLookDesign_DetailPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainLookDesign_DetailPrint]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainLookDesign_DetailPrint] AS SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName AS 看设计师, dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainPhotographed END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrdersPhotography.ID AS VID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_ReservationPhotographyTime)) AS 摄影时间, Ordpg_ReservationPhotographyTime AS 摄影时间查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName) AS 摄影师, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant) AS 摄影助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist) AS 化妆师, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant) AS 化妆助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision) AS 引导师, dbo.tb_ErpOrdersPhotography.Ordpg_Remark AS 录入备注, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Dispatcher) AS 安排人, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_DispatchTime)) AS 安排时间, (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed_DetailPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainPhotographed_DetailPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed_DetailPrint]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed_DetailPrint] AS SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 服装师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select top 1 Ordpg_ReservationPhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime ASC) AS 摄影时间, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyName) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyName != '''' group by Ordpg_ReservationPhotographyName for xml path('''')),1,1,'''')) as 摄影师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyAssistant != '''' group by Ordpg_ReservationPhotographyAssistant for xml path('''')),1,1,'''')) as 摄影助理, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupArtist != '''' group by Ordpg_ReservationMakeupArtist for xml path('''')),1,1,'''')) as 化妆师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupAssistant != '''' group by Ordpg_ReservationMakeupAssistant for xml path('''')),1,1,'''')) as 化妆助理, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationBootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationBootDivision != '''' group by Ordpg_ReservationBootDivision for xml path('''')),1,1,'''')) as 引导师 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPhotographed_DispatchPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainPhotographed_DispatchPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPhotographed_DispatchPrint]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainPhotographed_DispatchPrint] AS SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 服装师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select top 1 Ordpg_ReservationPhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyTime is not null order by Ordpg_ReservationPhotographyTime ASC) AS 摄影时间, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyName) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyName != '''' group by Ordpg_ReservationPhotographyName for xml path('''')),1,1,'''')) as 摄影师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationPhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationPhotographyAssistant != '''' group by Ordpg_ReservationPhotographyAssistant for xml path('''')),1,1,'''')) as 摄影助理, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupArtist != '''' group by Ordpg_ReservationMakeupArtist for xml path('''')),1,1,'''')) as 化妆师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationMakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationMakeupAssistant != '''' group by Ordpg_ReservationMakeupAssistant for xml path('''')),1,1,'''')) as 化妆助理, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_ReservationBootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_ReservationBootDivision != '''' group by Ordpg_ReservationBootDivision for xml path('''')),1,1,'''')) as 引导师, (select stuff((select '','' + Ordpg_Remark from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Remark!= '''' for xml path('''')),1,1,'''')) as 备注 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPickup') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainPickup END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPickup]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainPickup] AS SELECT dbo.tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop,Ord_Type, tb_ErpOrderProductList.ID AS PID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, CASE WHEN Ord_Type = ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.tb_ErpOrderProductList.OPlist_ProdName AS 商品名称, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReservationTakeTime)) AS 取件时间, OPlist_ReservationTakeTime AS 取件时间查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_PickupName) AS 取件人, dbo.fn_CheckTakePiecesStatus(dbo.tb_ErpOrderProductList.OPlist_PickupStatus) AS 取件状态, dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 完成状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderProductList.OPlist_ArrangeNmae) AS 安排人, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_ArrangeTime)) AS 安排时间 ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrderProductList ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrderProductList.OPlist_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainPickup_DetailPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainPickup_DetailPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainPickup_DetailPrint]')) EXEC dbo.sp_executesql @statement = N' create VIEW [dbo].[BView_CameraControlBookMainPickup_DetailPrint] AS SELECT dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_GetProductListCompletedStatus(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 完成状态, dbo.fn_GetProductList(dbo.tb_ErpOrderDigital.Ordv_Number, 5) AS 取件人, dbo.fn_GetProductListPickupDate(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 2) AS 取件时间 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainSelectDress') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainSelectDress END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainSelectDress]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainSelectDress] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName) AS 选礼服师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime)) AS 选礼服时间, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatcher) AS 安排人, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingDispatchTime)) AS 安排时间, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainWedding') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainWedding END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainWedding]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookMainWedding] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, dbo.tb_ErpWeddingService.Ws_Type, dbo.tb_ErpWeddingService.ID AS VID, dbo.tb_ErpOrder.Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.fn_ConvertDate(GregorianCalendar_DayForMarriage))) AS 婚期, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.tb_ErpWeddingService.Ws_ProdName AS 服务内容, dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ws_WeddingDate)) AS 服务日期, Ws_WeddingDate AS 服务日期查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2, dbo.tb_ErpWeddingService.Ws_Remark AS 服务备注, (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') --AND (dbo.tb_ErpWeddingService.Ws_Status = ''1'') OR --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_WeddingDate IS NOT NULL) OR --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''') OR --(dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpWeddingService.Ws_Serviceman2 <> '''') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookMainWedding_DetailPrint') BEGIN DROP VIEW [dbo].BView_CameraControlBookMainWedding_DetailPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookMainWedding_DetailPrint]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookMainWedding_DetailPrint] AS SELECT dbo.tb_ErpOrder.Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpWeddingService.Ws_ProdName AS 服务内容, dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDispatchDate) AS 服务时间, dbo.tb_ErpWeddingService.Ws_Serviceman1 AS 服务人员1, dbo.tb_ErpWeddingService.Ws_Serviceman2 AS 服务人员2 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationFilmSelectionRemind') BEGIN DROP VIEW [dbo].BView_CameraControlBookReservationFilmSelectionRemind END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationFilmSelectionRemind]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookReservationFilmSelectionRemind] AS SELECT dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckDateTimeReturn_Date(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime) AS 选片时间, dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 选片时间查询 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationLookDesignRemind') BEGIN DROP VIEW [dbo].BView_CameraControlBookReservationLookDesignRemind END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationLookDesignRemind]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookReservationLookDesignRemind] AS SELECT dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime) AS 看设计时间, dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime AS 看设计时间查询 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationPhotographedRemind') BEGIN DROP VIEW [dbo].BView_CameraControlBookReservationPhotographedRemind END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationPhotographedRemind]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_CameraControlBookReservationPhotographedRemind] AS SELECT dbo.tb_ErpOrder.Ord_DividedShop, Ordv_Number AS Ord_Number, dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber, CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称 ,Ordpg_Sights AS 拍摄名称 ,dbo.fn_CheckDateTimeReturn_Date(Ordpg_ReservationPhotographyTime) AS 拍摄时间 ,dbo.fn_CheckUserIDGetUserName(Ordpg_Dispatcher) AS 安排者 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_CameraControlBookReservationSelectDressRemind') BEGIN DROP VIEW [dbo].BView_CameraControlBookReservationSelectDressRemind END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_CameraControlBookReservationSelectDressRemind]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_CameraControlBookReservationSelectDressRemind] AS SELECT dbo.tb_ErpOrder.Ord_DividedShop, Ord_Number, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Sex_cs AS 客户性别, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, CASE Ord_Type WHEN ''1'' THEN (SELECT TOP 1 Ordpg_Sights FROM tb_ErpOrdersPhotography WHERE Ordpg_ViceNumber = Ordv_ViceNumber) ELSE '''' END AS 拍摄名称, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选礼服状态, dbo.fn_CheckUserIDGetUserName(Ordv_ReservationClothingName) AS 选礼服负责人, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 选礼服时间查询 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDesign') BEGIN DROP VIEW [dbo].BView_DoorCityDesign END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDesign]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_DoorCityDesign] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期, dbo.tb_ErpOrderDigital.Ordv_DesignerTime AS 设计查询日期, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.tb_ErpOrderDigital.Ordv_LookDesignClaim AS 看设计要求, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrange') BEGIN DROP VIEW [dbo].BView_DoorCityDigitalArrange END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrange]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_DoorCityDigitalArrange] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, --dbo.fn_GetPhotographerStatus(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 拍摄状态, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_EarlyRepairName <> '''' then Ordv_EarlyRepairName else Ordv_ReservationEarlyRepairName end)) AS 初修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修日期, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_FilmSelectionName <> '''' then Ordv_FilmSelectionName else Ordv_ReservationFilmSelectionName end)) AS 选片状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期, dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片查询日期, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_DesignerName <> '''' then Ordv_DesignerName else Ordv_ReservationDesignerName end)) AS 设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计日期, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_RefinementName <> '''' then Ordv_RefinementName else Ordv_ReservationRefinementName end)) AS 精修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修日期, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) + ''/'' + dbo.fn_CheckUserIDGetUserName((case when Ordv_LookDesignName <> '''' then Ordv_LookDesignName else Ordv_ReservationLookDesignName end)) AS 看设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期, dbo.tb_ErpOrderDigital.Ordv_LookDesignTime AS 看设计查询日期, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWork_A') BEGIN DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWork_A END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWork_A]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWork_A] AS SELECT tb_ErpOrderDigital.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName AS 初修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修期限, dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName AS 设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计期限, dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName AS 精修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修期限, dbo.tb_ErpOrderDigital.Ordv_ReservationSendPhotoName AS 发片师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationSendPhotoTime)) AS 发片期限 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A') BEGIN DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWork_NoDoTask_A] AS SELECT User_DividedShop, User_Name, Ord_EarlyRepairCout, Ord_RefinementCount, Ord_DesignerCount, Ord_SendPhotoCount FROM (SELECT User_DividedShop, User_Name,(SELECT COUNT(Ordv_ReservationEarlyRepairName) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_ReservationEarlyRepairName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_EarlyRepairStatus <> ''2'')) AS Ord_EarlyRepairCout, (SELECT COUNT(Ordv_ReservationRefinementName) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_2 WHERE (Ordv_ReservationRefinementName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_DesignerStatus <> ''2'')) AS Ord_RefinementCount, (SELECT COUNT(Ordv_ReservationDesignerName) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_ReservationDesignerName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_RefinementStatus <> ''2'')) AS Ord_DesignerCount, (Select COunt(Ordv_ReservationSendPhotoName) AS Expr1 from dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_3 where (Ordv_ReservationSendPhotoName = dbo.tb_ErpUser.User_EmployeeID) AND (Ordv_ReservationSendPhotoStatus <> ''2'')) AS Ord_SendPhotoCount FROM dbo.tb_ErpUser) AS tb WHERE (Ord_EarlyRepairCout > 0) OR (Ord_RefinementCount > 0) OR (Ord_DesignerCount > 0)OR (Ord_SendPhotoCount > 0) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityDigitalArrangeAnPaiWorkDigital') BEGIN DROP VIEW [dbo].BView_DoorCityDigitalArrangeAnPaiWorkDigital END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityDigitalArrangeAnPaiWorkDigital]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityDigitalArrangeAnPaiWorkDigital] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, Ord_Type, Ord_Number,dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName) + ''/'' + dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 初修完成期限, dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime AS 初修完成期限查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName) + ''/'' + dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 设计完成期限, dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime AS 设计完成期限查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName) + ''/'' + dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 精修完成期限, dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime AS 精修完成期限查询 FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName <> '''') OR (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) AND (dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName <> '''') OR (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrder.Ord_Type IN (''0'', ''1'', ''2'')) AND (dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName <> '''') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityFilmSelection') BEGIN DROP VIEW [dbo].BView_DoorCityFilmSelection END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityFilmSelection]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityFilmSelection] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.tb_ErpOrder.Ord_PlusPickNumber AS 加挑张数, dbo.fn_GetPlusPickAmount(dbo.tb_ErpOrder.Ord_Number) AS 加挑金额, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName) AS 选片师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期, dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 选片日期查询, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityFilmSelectionPrint') BEGIN DROP VIEW [dbo].BView_DoorCityFilmSelectionPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityFilmSelectionPrint]')) EXEC dbo.sp_executesql @statement = N' create VIEW [dbo].[BView_DoorCityFilmSelectionPrint] AS SELECT dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrder.Ord_Type, Cus_Name AS 客户姓名, Cus_Telephone AS 客户电话, M_Cus_Name AS 主客户姓名, M_Cus_Telephone AS 主客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '''' group by Ordpg_MakeupArtist for xml path('''')),1,1,'''')) as 化妆师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_BootDivision!= '''' group by Ordpg_BootDivision for xml path('''')),1,1,'''')) as 引导师, (select top 1 Ordpg_PhotographyTime from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄日期, dbo.tb_ErpOrderDigital.Ordv_ViceNumber FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityInputMemberCard') BEGIN DROP VIEW [dbo].BView_DoorCityInputMemberCard END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityInputMemberCard]')) EXEC dbo.sp_executesql @statement = N' Create VIEW [dbo].[BView_DoorCityInputMemberCard] AS Select ''0'' AS MainVice,Mc_Number,Mc_CradNumber, Mc_CardType, dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 1) AS Cus_Name, dbo.fn_ChineseToSpell(dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 1)) AS Cus_PName, dbo.fn_GetCustomer(dbo.tb_ErpMemberCard.Mc_CustomerNumber, 1, 3) AS Cus_Telephone from dbo.tb_ErpMemberCard where Mc_Status = ''1'' UNION select ''1'' AS MainVice,Mvc_ViceNumber AS Mc_Number,Mvc_ViceCardNumber AS Mc_CradNumber, (select Mc_CardType from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number) AS Mc_CardType, dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 1) AS Cus_Name, dbo.fn_ChineseToSpell(dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 1)) AS Cus_PName, dbo.fn_GetCustomer((select Mc_CustomerNumber from dbo.tb_ErpMemberCard where Mc_Number = Mvc_Number), 1, 3) AS Cus_Telephone from dbo.tb_ErpMemberCardViceCard where Mvc_Status = ''1'' ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityKePan') BEGIN DROP VIEW [dbo].BView_DoorCityKePan END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityKePan]')) EXEC dbo.sp_executesql @statement = N' create VIEW [dbo].[BView_DoorCityKePan] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 1) AS 刻盘次数, dbo.fn_GetKePan(dbo.tb_ErpOrderDigital.Ordv_ViceNumber, 2) AS 刻盘状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotographed') BEGIN DROP VIEW [dbo].BView_DoorCityPhotographed END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotographed]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_DoorCityPhotographed] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrdersPhotography.ID AS JID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_CustomerSource, dbo.tb_ErpOrder.Ord_PhotographyCategory, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.tb_ErpOrdersPhotography.Ordpg_Sights AS 拍摄名称, dbo.fn_CheckOrderPhotographyStatus(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus) AS 拍摄状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_Photographer) AS 摄影师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 拍摄日期, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 拍摄日期查询, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant) AS 拍摄助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist) AS 化妆师, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_MakeupAssistant) AS 化妆助理, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision) AS 引导师, dbo.fn_CheckOrderClothingStatus(dbo.tb_ErpOrderDigital.Ordv_ClothingStatus) AS 选衣状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (SELECT COUNT(tb_ErpOrdersPhotography_1.Ordpg_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrdersPhotography AS tb_ErpOrdersPhotography_1 LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON tb_ErpOrdersPhotography_1.Ordpg_ViceNumber = tb_ErpOrderDigital_1.Ordv_ViceNumber WHERE (tb_ErpOrderDigital_1.Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrints') BEGIN DROP VIEW [dbo].BView_DoorCityPhotosPrints END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrints]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrints] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, (select Cus_NamePinyin from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 姓名拼音1, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期, tb_ErpOrderPhotoPrints.ID AS PPID, Opps_PhotoName AS 相片名称, Opps_PhotoQuantity AS 数量, Opps_PhotoArea AS 面积,Opps_SendVendor AS 发出状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_SendTime)) AS 发出日期, dbo.fn_CheckPhotoPrintsReworkStatus(Opps_ReworkStatus) AS 返工状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_ReworkTime)) AS 返工日期, dbo.fn_CheckProductCompletedStatus(Opps_CompletedStatus) AS 完成状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_CompletedTime)) AS 完成日期, Case when (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number Left Join tb_ErpOrderPhotoPrints on Opps_OrderNumber = Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrintsMonthPrint') BEGIN DROP VIEW [dbo].BView_DoorCityPhotosPrintsMonthPrint END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrintsMonthPrint]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrintsMonthPrint] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrderPhotoPrints.ID AS PPID,Ord_Number, Ordv_ViceNumber,Ord_Type,dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber ) else '''' end) AS 拍摄名称, dbo.tb_ErpOrderPhotoPrints.Opps_PhotoName AS 相片名称, dbo.tb_ErpOrderPhotoPrints.Opps_PhotoQuantity AS 数量, dbo.tb_ErpOrderPhotoPrints.Opps_PhotoArea AS 面积m2, dbo.tb_ErpOrderPhotoPrints.Opps_SendVendor AS 是否发出, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_SendTime)) AS 发出日期, dbo.tb_ErpOrderPhotoPrints.Opps_SendTime AS 发出日期查询, dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedStatus) AS 是否完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime)) AS 完成日期, dbo.tb_ErpOrderPhotoPrints.Opps_CompletedTime AS 完成日期查询 ,(select Count(ID) from tb_ErpOrderPhotoPrints where Opps_OrderNumber = Ordv_ViceNumber) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrderPhotoPrints ON dbo.tb_ErpOrderPhotoPrints.Opps_OrderNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityPhotosPrintsPrintManage') BEGIN DROP VIEW [dbo].BView_DoorCityPhotosPrintsPrintManage END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityPhotosPrintsPrintManage]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityPhotosPrintsPrintManage] AS SELECT ID, Opps_OrderNumber, Opps_PhotoName AS 相片名称, Opps_PhotoQuantity AS 数量, Opps_PhotoArea AS 面积, Opps_SendStatus, Opps_SendVendor AS 是否发出, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_SendTime)) AS 发出日期, dbo.fn_CheckProductReworkStatus(Opps_ReworkStatus) + CASE [Opps_ReworkRemark] WHEN '''' THEN '''' ELSE ''/['' + [Opps_ReworkRemark] + '']'' END AS 返工, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_ReworkTime)) AS 返工日期, dbo.fn_CheckProductCompletedStatus(Opps_CompletedStatus) AS 是否完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Opps_CompletedTime)) AS 完成日期 FROM dbo.tb_ErpOrderPhotoPrints ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRefinedRepair') BEGIN DROP VIEW [dbo].BView_DoorCityRefinedRepair END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRefinedRepair]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityRefinedRepair] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when (select count(OPlist_IsExpedited) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber =Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_IsExpedited=''1'') = 0 then '''' else dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime((select top 1 OPlist_ExpeditedTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_ExpeditedTime != '''' order by OPlist_ExpeditedTime ASC))) end ) AS 加急日期, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 选片日期, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_RefinementName) AS 精修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 精修日期, dbo.tb_ErpOrderDigital.Ordv_RefinementTime AS 精修日期查询, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityRepairPiece') BEGIN DROP VIEW [dbo].BView_DoorCityRepairPiece END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityRepairPiece]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_DoorCityRepairPiece] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, dbo.fn_GetProductExpedited(dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AS 加急, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄日期, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName) AS 初修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 初修日期, dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime AS 初修日期查询, dbo.fn_CheckOrderEarlyRepairStatus(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckOrderFilmSelectionStatus(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckOrderRefinementStatus(dbo.tb_ErpOrderDigital.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePiece') BEGIN DROP VIEW [dbo].BView_DoorCityTotakePiece END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePiece]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePiece] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, Ord_Type, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (Ord_SeriesPrice - (Case when (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) is null then 0 else (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =Ord_Number and Pay_Category in (''全款'',''后期收款'',''预约收款'',''预约补款'')) end) + (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = Ord_Number)) AS 欠款, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckOrderDesignerStatus(dbo.tb_ErpOrderDigital.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 设计日期, dbo.fn_CheckOrderLookDesignStatus(dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus) AS 看设计状态, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_LookDesignName) AS 看设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 看设计日期, (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'' and OPlist_CompletedStatus = ''1'')>0 then ''未完'' else (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''0'') > 0 then ''未完'' else (case when (select count(OPlist_CompletedStatus) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_CompletedStatus = ''1'') > 0 then ''OK'' else '''' end )end )end ) AS 是否完成, (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期, (select top 1 OPlist_PickupTime from dbo.tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type=''2'' and OPlist_PickupTime != '''' order by OPlist_PickupTime DESC) AS 取件日期查询, tb_ErpOrderProductList.ID AS OPID, OPlist_ProdName AS 商品名称, dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) AS 商品取件日期, OPlist_SendVendor AS 是否发出, dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) AS 是否返工, dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 商品完成状态, dbo.fn_CheckProductTakePiecesStatus(OPlist_PickupStatus) AS 是否取走 ,Case when (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber)>0 then (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber) else (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE Ordv_Number = dbo.tb_ErpOrder.Ord_Number) end AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number Left Join tb_ErpOrderProductList ON OPlist_ViceNumber = Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceHairPiece') BEGIN DROP VIEW [dbo].BView_DoorCityTotakePieceHairPiece END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceHairPiece]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceHairPiece] AS SELECT ID, OPlist_ViceNumber, OPlist_ProdName AS 商品名称, OPlist_ProdQuantity AS 数量, dbo.fn_CheckIsExpedited(OPlist_IsExpedited) AS 加急, OPlist_SendStatus, OPlist_SendVendor AS 发出, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_SendTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_SendName) AS 发出日期, OPlist_SendName AS OPlist_SendNameCode, dbo.fn_CheckProductReworkStatus(OPlist_ReworkStatus) + CASE [OPlist_ReworkRemark] WHEN '''' THEN '''' ELSE ''['' + [OPlist_ReworkRemark] + '']'' END AS 返工, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_ReworkTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_ReworName) AS 返工日期, OPlist_ReworName AS OPlist_ReworNameCode, OPlist_CompletedStatus, dbo.fn_CheckProductCompletedStatus(OPlist_CompletedStatus) AS 完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_CompletedTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_CompletedName) AS 完成日期, OPlist_CompletedName AS OPlist_CompletedNameCode, dbo.fn_CheckTakePiecesStatus(OPlist_PickupStatus) AS 取走, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) + ''/'' + dbo.fn_CheckUserIDGetUserName(OPlist_PickupName) AS 取走日期, OPlist_PickupName AS OPlist_PickupNameCode FROM dbo.tb_ErpOrderProductList WHERE (OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPieces') BEGIN DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPieces END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPieces]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthPieces] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, dbo.tb_ErpOrderProductList.ID AS TPID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrderDigital.Ordv_DesignerName) AS 设计师, OPlist_ProdNumber, OPlist_ProdName AS 产品名称, OPlist_Class, (select Sc_ClassName from tb_ErpSystemCategory where Sc_ClassCode = OPlist_Class) AS 商品类别, dbo.tb_ErpOrderProductList.OPlist_ProdQuantity AS 数量, dbo.tb_ErpOrderProductList.OPlist_CostPrice AS 制作费用, dbo.tb_ErpOrderProductList.OPlist_SendVendor AS 是否发出, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_SendTime)) AS 发出日期, dbo.tb_ErpOrderProductList.OPlist_SendTime AS 发出日期查询, dbo.fn_CheckProductCompletedStatus(dbo.tb_ErpOrderProductList.OPlist_CompletedStatus) AS 是否完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_CompletedTime)) AS 完成日期, dbo.tb_ErpOrderProductList.OPlist_CompletedTime AS 完成日期查询, (select Count(ID) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber AND OPlist_Type = ''2'') AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrderProductList ON dbo.tb_ErpOrderProductList.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthPiecesNotBack') BEGIN DROP VIEW [dbo].BView_DoorCityTotakePieceMonthPiecesNotBack END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthPiecesNotBack] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type,tb_ErpOrderProductList_1.ID AS PPID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称, tb_ErpOrderProductList_1.OPlist_Class, (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别, tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_CostPrice AS 制作费用, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_SendTime)) AS 发出日期, tb_ErpOrderProductList_1.OPlist_SendTime AS 发出日期查询, dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期, (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_DoorCityTotakePieceMonthReworkStatistic') BEGIN DROP VIEW [dbo].BView_DoorCityTotakePieceMonthReworkStatistic END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_DoorCityTotakePieceMonthReworkStatistic]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_DoorCityTotakePieceMonthReworkStatistic] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Type, tb_ErpOrderProductList_1.ID AS PPID, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, tb_ErpOrderProductList_1.OPlist_ProdNumber, tb_ErpOrderProductList_1.OPlist_ProdName AS 产品名称, tb_ErpOrderProductList_1.OPlist_Class, (SELECT Sc_ClassName FROM dbo.tb_ErpSystemCategory WHERE (Sc_ClassCode = tb_ErpOrderProductList_1.OPlist_Class)) AS 商品类别, tb_ErpOrderProductList_1.OPlist_ProdQuantity AS 数量, tb_ErpOrderProductList_1.OPlist_SendVendor AS 是否发出, dbo.fn_CheckProductReworkStatus(tb_ErpOrderProductList_1.OPlist_ReworkStatus) + CASE OPlist_ReworkRemark WHEN '''' THEN '''' ELSE ''/['' + OPlist_ReworkRemark + '']'' END AS 是否返工, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_ReworkTime)) AS 返工日期, tb_ErpOrderProductList_1.OPlist_ReworkTime AS 返工日期查询, dbo.fn_CheckProductCompletedStatus(tb_ErpOrderProductList_1.OPlist_CompletedStatus) AS 是否完成, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderProductList_1.OPlist_CompletedTime)) AS 完成日期, (SELECT COUNT(ID) AS Expr1 FROM dbo.tb_ErpOrderProductList WHERE (OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber) AND (OPlist_Type = ''2'')) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number LEFT OUTER JOIN dbo.tb_ErpOrderProductList AS tb_ErpOrderProductList_1 ON tb_ErpOrderProductList_1.OPlist_ViceNumber = dbo.tb_ErpOrderDigital.Ordv_ViceNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Class = ''1'') AND (tb_ErpOrderProductList_1.OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_IntentClientGroup') BEGIN DROP VIEW [dbo].BView_IntentClientGroup END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_IntentClientGroup]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_IntentClientGroup] AS SELECT GP_CustomerGroupID, GP_OrderNumber, GP_GroupType, case when isnull((select Ord_SinceOrderNumber from tb_ErpOrder where Ord_Number = GP_OrderNumber),'''') = '''' then GP_OrderNumber else (select Ord_SinceOrderNumber from tb_ErpOrder where Ord_Number = GP_OrderNumber) end as 订单号, Cus_Name AS 客户姓名, Cus_Name_py, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, dbo.fn_CheckClientIntentType(GP_CustomerType) AS 客户意向类型, dbo.fn_CheckDateTime(GP_CreateDatetime) AS 下单时间 from tempTB_AggregationCustomer ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkBootDivision_No') BEGIN DROP VIEW [dbo].BView_MyWorkBootDivision_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkBootDivision_No]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkBootDivision_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ReservationBootDivision = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkBootDivision_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkBootDivision_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkBootDivision_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkBootDivision_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_BootDivision = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkClothing_No') BEGIN DROP VIEW [dbo].BView_MyWorkClothing_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkClothing_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkClothing_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName AS 员工编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationClothingTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationClothingName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_ClothingStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkClothing_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkClothing_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkClothing_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkClothing_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpOrderDigital.Ordv_ClothingName AS 员工编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ClothingTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ClothingTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ClothingName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_ClothingStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkDesigner_No') BEGIN DROP VIEW [dbo].BView_MyWorkDesigner_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkDesigner_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkDesigner_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationDesignerName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_DesignerStatus IN (''0'', ''1'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkDesigner_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkDesigner_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkDesigner_Ok]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_MyWorkDesigner_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_DesignerName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_DesignerTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_DesignerTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_DesignerName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_DesignerStatus = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkEarlyRepairName_No') BEGIN DROP VIEW [dbo].BView_MyWorkEarlyRepairName_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkEarlyRepairName_No]')) EXEC dbo.sp_executesql @statement = N'create VIEW [dbo].[BView_MyWorkEarlyRepairName_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationEarlyRepairName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus IN (''0'', ''1'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkEarlyRepairName_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkEarlyRepairName_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkEarlyRepairName_Ok]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkEarlyRepairName_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_EarlyRepairTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_EarlyRepairName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_EarlyRepairStatus = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkFilmSelection_No') BEGIN DROP VIEW [dbo].BView_MyWorkFilmSelection_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkFilmSelection_No]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkFilmSelection_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationFilmSelectionName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkFilmSelection_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkFilmSelection_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkFilmSelection_Ok]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkFilmSelection_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_FilmSelectionTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_FilmSelectionName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_FilmSelectionStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkLookDesign_No') BEGIN DROP VIEW [dbo].BView_MyWorkLookDesign_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkLookDesign_No]')) EXEC dbo.sp_executesql @statement = N'CREATE VIEW [dbo].[BView_MyWorkLookDesign_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationLookDesignName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus IN (''0'', ''2'', ''3'', ''4'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkLookDesign_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkLookDesign_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkLookDesign_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkLookDesign_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_LookDesignName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_LookDesignTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_LookDesignTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_LookDesignName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_LookDesignStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupArtist_No') BEGIN DROP VIEW [dbo].BView_MyWorkMakeupArtist_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupArtist_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkMakeupArtist_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupArtist = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupArtist_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkMakeupArtist_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupArtist_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkMakeupArtist_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupAssistant_No') BEGIN DROP VIEW [dbo].BView_MyWorkMakeupAssistant_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupAssistant_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkMakeupAssistant_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ReservationMakeupAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkMakeupAssistant_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkMakeupAssistant_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkMakeupAssistant_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkMakeupAssistant_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_MakeupArtist AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_MakeupAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyAssistant_No') BEGIN DROP VIEW [dbo].BView_MyWorkPhotographyAssistant_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyAssistant_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkPhotographyAssistant_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyAssistant_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkPhotographyAssistant_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyAssistant_Ok]')) EXEC dbo.sp_executesql @statement = N' create VIEW [dbo].[BView_MyWorkPhotographyAssistant_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyAssistant = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyName_No') BEGIN DROP VIEW [dbo].BView_MyWorkPhotographyName_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyName_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkPhotographyName_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_ReservationPhotographyName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPhotographyName_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkPhotographyName_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPhotographyName_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkPhotographyName_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderDigital.Ordv_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrdersPhotography.Ordpg_Photographer AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime)) AS 工作时间, dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrdersPhotography ON dbo.tb_ErpOrdersPhotography.Ordpg_Photographer = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ViceNumber = dbo.tb_ErpOrdersPhotography.Ordpg_ViceNumber LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrdersPhotography.Ordpg_PhotographyStatus = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPickup_No') BEGIN DROP VIEW [dbo].BView_MyWorkPickup_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPickup_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkPickup_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderProductList.OPlist_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderProductList.OPlist_ReservationTakeName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_ReservationTakeTime)) AS 工作时间, dbo.tb_ErpOrderProductList.OPlist_ReservationTakeTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderProductList ON dbo.tb_ErpOrderProductList.OPlist_ReservationTakeName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderProductList.OPlist_OrderNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderProductList.OPlist_PickupStatus = ''0'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkPickup_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkPickup_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkPickup_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkPickup_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpOrderProductList.OPlist_ViceNumber, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderProductList.OPlist_PickupName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderProductList.OPlist_PickupTime)) AS 工作时间, dbo.tb_ErpOrderProductList.OPlist_PickupTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderProductList ON dbo.tb_ErpOrderProductList.OPlist_PickupName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderProductList.OPlist_OrderNumber left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderProductList.OPlist_PickupStatus = ''1'') AND (dbo.tb_ErpOrderProductList.OPlist_Type = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkRefinement_No') BEGIN DROP VIEW [dbo].BView_MyWorkRefinement_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkRefinement_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkRefinement_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_ReservationRefinementName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_RefinementStatus IN (''0'', ''1'')) ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkRefinement_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkRefinement_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkRefinement_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkRefinement_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, dbo.tb_ErpUser.User_DividedShop AS 分店编号, dbo.tb_ErpUser.User_Name AS 员工姓名, dbo.tb_ErpOrderDigital.Ordv_RefinementName AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrderDigital.Ordv_RefinementTime)) AS 工作时间, dbo.tb_ErpOrderDigital.Ordv_RefinementTime AS 工作时间查询 FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpOrderDigital ON dbo.tb_ErpOrderDigital.Ordv_RefinementName = dbo.tb_ErpUser.User_EmployeeID LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpOrderDigital.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrderDigital.Ordv_RefinementStatus = ''2'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkService_No') BEGIN DROP VIEW [dbo].BView_MyWorkService_No END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkService_No]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkService_No] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, tb1.User_DividedShop AS 分店编号, tb1.User_Name AS 员工姓名, tb1.Ws_Status, tb1.Ws_Serviceman AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb1.Ws_WeddingDate)) AS 工作时间, tb1.Ws_WeddingDate AS 工作时间查询 FROM (SELECT dbo.tb_ErpWeddingService.Ws_Number, dbo.tb_ErpUser.User_DividedShop, dbo.tb_ErpUser.User_Name, dbo.tb_ErpWeddingService.Ws_WeddingDate, dbo.tb_ErpWeddingService.Ws_Status, dbo.tb_ErpWeddingService.Ws_Serviceman1 AS Ws_Serviceman FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpWeddingService.Ws_Serviceman1 = dbo.tb_ErpUser.User_EmployeeID WHERE (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''') UNION SELECT tb_ErpWeddingService_1.Ws_Number, tb_ErpUser_1.User_DividedShop, tb_ErpUser_1.User_Name, tb_ErpWeddingService_1.Ws_WeddingDate, tb_ErpWeddingService_1.Ws_Status, tb_ErpWeddingService_1.Ws_Serviceman2 AS Ws_Serviceman FROM dbo.tb_ErpUser AS tb_ErpUser_1 LEFT OUTER JOIN dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 ON tb_ErpWeddingService_1.Ws_Serviceman2 = tb_ErpUser_1.User_EmployeeID WHERE (tb_ErpWeddingService_1.Ws_Serviceman2 <> '''')) AS tb1 LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = tb1.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (tb1.Ws_Status = ''0'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_MyWorkService_Ok') BEGIN DROP VIEW [dbo].BView_MyWorkService_Ok END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_MyWorkService_Ok]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_MyWorkService_Ok] AS SELECT tb_ErpOrder.ID, CASE [Ord_SinceOrderNumber] WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, tb1.User_DividedShop AS 分店编号, tb1.User_Name AS 员工姓名, tb1.Ws_Status, tb1.Ws_Serviceman AS 员工编号, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb1.Ws_WeddingDate)) AS 工作时间, tb1.Ws_WeddingDate AS 工作时间查询 FROM (SELECT dbo.tb_ErpWeddingService.Ws_Number, dbo.tb_ErpUser.User_DividedShop, dbo.tb_ErpUser.User_Name, dbo.tb_ErpWeddingService.Ws_WeddingDate, dbo.tb_ErpWeddingService.Ws_Status, dbo.tb_ErpWeddingService.Ws_Serviceman1 AS Ws_Serviceman FROM dbo.tb_ErpUser LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpWeddingService.Ws_Serviceman1 = dbo.tb_ErpUser.User_EmployeeID WHERE (dbo.tb_ErpWeddingService.Ws_Serviceman1 <> '''') UNION SELECT tb_ErpWeddingService_1.Ws_Number, tb_ErpUser_1.User_DividedShop, tb_ErpUser_1.User_Name, tb_ErpWeddingService_1.Ws_WeddingDate, tb_ErpWeddingService_1.Ws_Status, tb_ErpWeddingService_1.Ws_Serviceman2 AS Ws_Serviceman FROM dbo.tb_ErpUser AS tb_ErpUser_1 LEFT OUTER JOIN dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 ON tb_ErpWeddingService_1.Ws_Serviceman2 = tb_ErpUser_1.User_EmployeeID WHERE (tb_ErpWeddingService_1.Ws_Serviceman2 <> '''')) AS tb1 LEFT OUTER JOIN dbo.tb_ErpOrder ON dbo.tb_ErpOrder.Ord_Number = tb1.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (tb1.Ws_Status = ''1'') ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_OrderReport') BEGIN DROP VIEW [dbo].BView_OrderReport END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_OrderReport] AS SELECT tb_ErpOrder.ID,dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, tb_ErpOrderDigital_1.Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_Class, Ord_Type, Ord_OrderClass, CASE Ord_SinceOrderNumber WHEN '''' THEN Ord_Number ELSE Ord_SinceOrderNumber END AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, [Age_String] AS 年龄, [Age_Day] AS 天, [Age_Year] AS 年, dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别, dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, (case when Ord_Type = ''1'' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else '''' end) as 拍摄名称, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_Photographer!= '''' group by Ordpg_Photographer for xml path('''')),1,1,'''')) as 摄影师, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_MakeupArtist!= '''' group by Ordpg_MakeupArtist for xml path('''')),1,1,'''')) as 化妆师, (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordpg_PhotographyTime)) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyTime is not null order by Ordpg_PhotographyTime DESC) AS 拍摄时间, (case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''2'') > 0 then ''拍摄中'' else case when (select Count(Ordpg_PhotographyStatus) from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber and Ordpg_PhotographyStatus = ''1'') > 0 then ''OK'' else ''未拍'' end end) AS 拍照状态, dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_EarlyRepairName) AS 初修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_EarlyRepairTime)) AS 初修时间, dbo.fn_CheckOrderEarlyRepairStatus(tb_ErpOrderDigital_1.Ordv_EarlyRepairStatus) AS 初修状态, dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_FilmSelectionName) AS 选片师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ordv_FilmSelectionTime)) AS 选片时间, dbo.fn_CheckOrderFilmSelectionStatus(tb_ErpOrderDigital_1.Ordv_FilmSelectionStatus) AS 选片状态, dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_DesignerName) AS 设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_DesignerTime)) AS 设计时间, dbo.fn_CheckOrderDesignerStatus(tb_ErpOrderDigital_1.Ordv_DesignerStatus) AS 设计状态, dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_RefinementName) AS 精修师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_RefinementTime)) AS 精修时间, dbo.fn_CheckOrderRefinementStatus(tb_ErpOrderDigital_1.Ordv_RefinementStatus) AS 精修状态, dbo.fn_CheckUserIDGetUserName(tb_ErpOrderDigital_1.Ordv_LookDesignName) AS 看设计师, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(tb_ErpOrderDigital_1.Ordv_LookDesignTime)) AS 看设计时间, dbo.fn_CheckOrderLookDesignStatus(tb_ErpOrderDigital_1.Ordv_LookDesignStatus) AS 看设计状态, tb_ErpOrderDigital_1.Ordv_LookDesignClaim AS 看设计要求, (case when (select count(OPlist_PickupStatus) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupStatus = ''0'') >0 then ''未取'' else ''OK'' end) AS 取件状态, (select top 1 dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(OPlist_PickupTime)) from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = ''2'' and OPlist_PickupTime != null order by OPlist_PickupTime) AS 取件日期, dbo.tb_ErpOrder.Ord_Remark AS 备注, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(Ord_CreateDateTime)) AS 下单日期, Ord_CreateDateTime AS 下单日期查询, (SELECT COUNT(Ordv_ViceNumber) AS Expr1 FROM dbo.tb_ErpOrderDigital WHERE (Ordv_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpOrderDigital AS tb_ErpOrderDigital_1 ON dbo.tb_ErpOrder.Ord_Number = tb_ErpOrderDigital_1.Ordv_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber where Ord_Type <> ''3'' ' GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'BView_OrderReport_Server') BEGIN DROP VIEW [dbo].BView_OrderReport_Server END GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[BView_OrderReport_Server]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[BView_OrderReport_Server] AS SELECT tb_ErpOrder.ID, dbo.tb_ErpOrder.Ord_DividedShop, dbo.tb_ErpOrder.Ord_Number, dbo.tb_ErpWeddingService.ID AS Ordv_ViceNumber, dbo.tb_ErpOrder.Ord_Class, dbo.tb_ErpOrder.Ord_Type,Ord_OrderClass, dbo.tb_ErpOrder.Ord_Number AS 订单号, dbo.fn_CheckOrderType(dbo.tb_ErpOrder.Ord_Type) AS 订单类型, Cus_Name AS 客户姓名, Cus_Name_py AS 客户拼音, Cus_Sex_cs AS 客户性别, Cus_Telephone AS 客户电话, [Age_String] AS 年龄, [Age_Day] AS 天, [Age_Year] AS 年, dbo.tb_ErpOrder.Ord_CustomerSource AS 客户来源, dbo.tb_ErpOrder.Ord_PhotographyCategory AS 套系类别, dbo.tb_ErpOrder.Ord_SeriesName AS 套系名称, dbo.tb_ErpOrder.Ord_SeriesPrice AS 套系价格, (select stuff((select '','' + dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber = Ord_Number for xml path('''')),1,1,'''')) as 接单人, dbo.fn_ChineseToSpell((select stuff((select '',''+ dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('''')),1,1,''''))) as 接单人拼音, dbo.tb_ErpWeddingService.Ws_ProdName AS 服务名称, dbo.tb_ErpWeddingService.Ws_ProdQuantity AS 数量, dbo.fn_CheckWeddingServiceStatus(dbo.tb_ErpWeddingService.Ws_Status) AS 服务状态, dbo.fn_CheckDateTime(dbo.tb_ErpWeddingService.Ws_WeddingDate) AS 服务时间, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman1) AS 服务人员1, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpWeddingService.Ws_Serviceman2) AS 服务人员2, dbo.fn_CheckUserIDGetUserName(dbo.tb_ErpOrder.Ord_CreateName) AS 录入员, dbo.fn_CheckDateTimeReturn_Date(dbo.fn_CheckDateTime(dbo.tb_ErpOrder.Ord_CreateDateTime)) AS 下单日期, dbo.tb_ErpOrder.Ord_CreateDateTime AS 下单日期查询, (SELECT COUNT(Ws_Number) AS Expr1 FROM dbo.tb_ErpWeddingService AS tb_ErpWeddingService_1 WHERE (Ws_Number = dbo.tb_ErpOrder.Ord_Number)) AS Ord_ViceOrderCount FROM dbo.tb_ErpOrder LEFT OUTER JOIN dbo.tb_ErpWeddingService ON dbo.tb_ErpOrder.Ord_Number = dbo.tb_ErpWeddingService.Ws_Number left join tempTB_AggregationCustomer on tb_ErpOrder.Ord_Number = GP_OrderNumber WHERE (dbo.tb_ErpOrder.Ord_Type IN (''3'')) ' GO -----胡工--- IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital') BEGIN DROP VIEW [dbo].View_OrdersWageDigital END GO create view View_OrdersWageDigital as select tb_ErpOrderDigital.Id , Ordv_Number ,Ordv_ViceNumber ,Ordv_DigitalNumber ,Ord_Number ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称 ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称 ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话 ,Ordv_ClothingName as 礼服师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师 ,Ordv_ClothingStatus as 礼服师状态 ,Ordv_ClothingTime as 选衣时间 , Ordv_FilmSelectionName as 选片师ID , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师 , Ordv_FilmSelectionStatus as 选片状态 , Ordv_FilmSelectionTime as 选片时间 , Ordv_EarlyRepairName as 初修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师 , Ordv_EarlyRepairStatus as 初修状态 , Ordv_EarlyRepairTime as 初修时间 , Ordv_RefinementName as 精修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师 , Ordv_RefinementStatus as 精修状态 , Ordv_RefinementTime as 精修时间 ,Ordv_LookDesignName as 看设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师 ,Ordv_LookDesignStatus as 看设计状态 ,Ordv_LookDesignTime as 看设计时间 ,Ordv_DesignerName as 设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师 ,Ordv_DesignerStatus as 设计状态 , Ordv_DesignerTime as 设计时间 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期 from tb_ErpOrderDigital left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography') BEGIN DROP VIEW [dbo].View_OrdersWagePhotography END GO create view View_OrdersWagePhotography as SELECT tb_ErpOrdersPhotography.ID ,Ordpg_Number ,Ordpg_ViceNumber ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户名称 ,(select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as 客户电话 ,Ordpg_Sights as 拍摄名称 --,Ordpg_SightsLevel --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName ,Ordpg_SightsType as 景点类别 ,Ordpg_ApparelQuantity as 服装套数 ,Ordpg_Photographer as 摄影师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称 ,Ordpg_PhotographyTime as 拍摄时间 ,Ordpg_PhotographyStatus as 拍摄状态 --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName ,Ordpg_PhotographyAssistant as 摄影助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称 ,Ordpg_MakeupArtist as 化妆师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称 ,Ordpg_MakeupAssistant as 化妆助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称 ,Ordpg_BootDivision as 引导师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称 --,Ordpg_ReservationPhotographyName --,Ordpg_ReservationPhotographyTime --,Ordpg_ReservationPhotographyAssistant --,Ordpg_ReservationMakeupArtist --,Ordpg_ReservationMakeupAssistant --,Ordpg_ReservationBootDivision FROM tb_ErpOrdersPhotography left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionReturningMattersSet') BEGIN DROP VIEW [dbo].View_ErpSatisfactionReturningMattersSet END GO create view View_ErpSatisfactionReturningMattersSet as SELECT tb_ErpSatisfactionReturningMattersSet.ID ,Sfrms_SurveySetID ,Sfrms_Contents ,Sfrms_EnableStatus ,Sfrms_CreateTime ,Sfrms_CreateName ,Sfrms_UpdateTime ,Sfrms_UpdateName ,Sfss_Name ,(CASE sfrms_EnableStatus WHEN '0' THEN '启用' ELSE '不启用' END ) as sfrms_EnableStatusName FROM tb_ErpSatisfactionReturningMattersSet left join tb_ErpSatisfactionSurveySet on tb_ErpSatisfactionReturningMattersSet.Sfrms_SurveySetID=tb_ErpSatisfactionSurveySet.ID GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey') BEGIN DROP VIEW [dbo].View_ErpSatisfactionSurvey END GO create view View_ErpSatisfactionSurvey as SELECT tb_ErpSatisfactionSurvey.ID ,Sfs_OrderNumber ,Sfs_OrderNumberDeputy ,Sfs_EmployeeID ,(select [User_Name] from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName ,Sfs_Type ,Sfs_SurveySetID ,Sfss_Name as Sfs_SurveySetName ,Sfs_ReturningMattersSetID ,Sfrms_Contents ,Sfs_RatingSetID ,Sfrs_Name as Sfs_RatingSetName ,Sfs_Remark ,Sfs_CreateName as Sfs_CreateNameID ,(select [User_Name] from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName ,Sfs_CreateTime ,Sfs_UpdateTime ,Sfs_UpdateName as Sfs_UpdateNameID ,(select [User_Name] from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName ,Ord_CustomerName1 ,Ord_CustomerSex1 ,Ord_CustomerTelephone1 ,Sfrs_Scores ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount FROM tb_ErpSatisfactionSurvey left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OtherCustomers') BEGIN DROP VIEW [dbo].View_OtherCustomers END GO Create View View_OtherCustomers as SELECT distinct Tsorder_CustomerNumber , [Tsorder_CustomerName] ,[Tsorder_Telephone] ,Cus_NamePinyin FROM Vw_TwoSalesOrder GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_Customer_PaymentOrdersTwo') BEGIN DROP VIEW [dbo].View_Customer_PaymentOrdersTwo END GO Create view [dbo].[View_Customer_PaymentOrdersTwo] as select ID, Ord_Number, Ord_DividedShop, Ord_Type, Ord_SeriesName, Ord_SeriesPrice, Ord_Class, Ord_CustomerListID, Ord_MainContact, (select Cus_Name from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerName1, (select Cus_Sex from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerSex1, (select Cus_Telephone from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) as Ord_CustomerTelephone1, (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END ) as Ord_CustomerListID2 , (select Cus_Name from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerName2, (select Cus_Telephone from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber) as Ord_CustomerTelephone2, (select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson, (select [Cus_NamePinyin] from tb_ErpCustomer where Ord_MainContact=Cus_CustomerNumber) AS name1, ((select [Cus_NamePinyin] from tb_ErpCustomer where (CASE Ord_Type WHEN '0' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) WHEN '1' THEN ( select substring(Ord_CustomerListID,charindex(',',Ord_CustomerListID+',')+1,charindex(',',Ord_CustomerListID+',')-1)) ELSE '' END )=Cus_CustomerNumber)) AS name2, (select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID, Ord_CreateDatetime ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount from tb_ErpOrder GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpPieceCommissionRecords') BEGIN DROP VIEW [dbo].View_ErpPieceCommissionRecords END GO Create view [dbo].[View_ErpPieceCommissionRecords] as SELECT tb_ErpPieceCommissionRecords.ID ,Pcr_OrderNumber ,Pcr_DigitalDivision ,Pcr_Date ,Pcr_CompletionContents ,Pcr_Quantity ,Pcr_CreateTime ,Pcr_EntryPeople ,Pcr_Type ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName ,Ord_Type ,Ord_Class ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone ,Ord_SeriesName ,Ord_SeriesPrice FROM tb_ErpPieceCommissionRecords left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePaymentRecords') BEGIN DROP VIEW [dbo].View_OrdersWagePaymentRecords END GO Create VIEW [dbo].[View_OrdersWagePaymentRecords] AS SELECT View_ErpPayment.ID ,Pay_OrdNumber ,Pay_AmountOf ,Pay_OpenSingle ,Pay_ThePayee ,Pay_PaymentMethod ,Pay_OrdersLocation ,Pay_ReceivableProject ,Pay_CustomNumber ,Pay_Remark ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime ,Pay_Category ,Pay_TwoPinsCategory ,Pay_UserName ,Pay_ThePayeeName ,Pay_PaymentMethodName ,Pay_TwoPinsCategoryName ,Pay_FinancialAuditdPeople ,Pay_FinancialAudit ,Pay_FinancialAuditdPeopleName ,Pay_ShootingName ,Ord_Number ,Ord_DividedShop ,Ord_Type ,Ord_Class , Ord_CustomerName1 ,name1 ,Ord_CustomerTelephone1 ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName ,Ord_CreateDatetime ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type ,Ord_SeriesName FROM View_ErpPayment left join View_Customer_PaymentOrdersTwo on View_ErpPayment.Pay_OrdNumber=View_Customer_PaymentOrdersTwo.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_ErpSatisfactionSurvey') BEGIN DROP VIEW [dbo].View_ErpSatisfactionSurvey END GO Create view [dbo].[View_ErpSatisfactionSurvey] as SELECT tb_ErpSatisfactionSurvey.ID ,Sfs_OrderNumber ,Sfs_OrderNumberDeputy ,Sfs_EmployeeID ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName ,Sfs_Type ,Sfs_SurveySetID ,Sfss_Name as Sfs_SurveySetName ,Sfs_ReturningMattersSetID ,Sfrms_Contents ,Sfs_RatingSetID ,Sfrs_Name as Sfs_RatingSetName ,Sfs_Remark ,Sfs_CreateName as Sfs_CreateNameID ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName ,Sfs_CreateTime ,Sfs_UpdateTime ,Sfs_UpdateName as Sfs_UpdateNameID ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName , Ord_CustomerName1 ,name1 ,Ord_CustomerTelephone1 ,Sfrs_Scores ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount FROM tb_ErpSatisfactionSurvey left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID left join View_Customer_PaymentOrdersTwo on Sfs_OrderNumber=Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWageDigital') BEGIN DROP VIEW [dbo].View_OrdersWageDigital END GO Create view [dbo].[View_OrdersWageDigital] as select tb_ErpOrderDigital.Id , Ordv_Number ,Ordv_ViceNumber ,Ordv_DigitalNumber ,Ord_Number ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称 ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称 ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话 ,Ordv_ClothingName as 礼服师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师 ,Ordv_ClothingStatus as 礼服师状态 ,Ordv_ClothingTime as 选衣时间 , Ordv_FilmSelectionName as 选片师ID , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师 , Ordv_FilmSelectionStatus as 选片状态 , Ordv_FilmSelectionTime as 选片时间 , Ordv_EarlyRepairName as 初修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师 , Ordv_EarlyRepairStatus as 初修状态 , Ordv_EarlyRepairTime as 初修时间 , Ordv_RefinementName as 精修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师 , Ordv_RefinementStatus as 精修状态 , Ordv_RefinementTime as 精修时间 ,Ordv_LookDesignName as 看设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师 ,Ordv_LookDesignStatus as 看设计状态 ,Ordv_LookDesignTime as 看设计时间 ,Ordv_DesignerName as 设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师 ,Ordv_DesignerStatus as 设计状态 , Ordv_DesignerTime as 设计时间 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期 ,(case Ord_Type when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) else '' end) as 未拍个数 from tb_ErpOrderDigital left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'View_OrdersWagePhotography') BEGIN DROP VIEW [dbo].View_OrdersWagePhotography END GO Create view [dbo].[View_OrdersWagePhotography] as SELECT tb_ErpOrdersPhotography.ID ,Ordpg_Number ,Ordpg_ViceNumber ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称 ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话 ,Ordpg_Sights as 拍摄名称 --,Ordpg_SightsLevel --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName ,Ordpg_SightsType as 景点类别 ,Ordpg_ApparelQuantity as 服装套数 ,Ordpg_Photographer as 摄影师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称 ,Ordpg_PhotographyTime as 拍摄时间 ,Ordpg_PhotographyStatus as 拍摄状态 --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName ,Ordpg_PhotographyAssistant as 摄影助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称 ,Ordpg_MakeupArtist as 化妆师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称 ,Ordpg_MakeupAssistant as 化妆助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称 ,Ordpg_BootDivision as 引导师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称 --,Ordpg_ReservationPhotographyName --,Ordpg_ReservationPhotographyTime --,Ordpg_ReservationPhotographyAssistant --,Ordpg_ReservationMakeupArtist --,Ordpg_ReservationMakeupAssistant --,Ordpg_ReservationBootDivision FROM tb_ErpOrdersPhotography left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_Customer_PaymentOrders') BEGIN DROP VIEW [dbo].Vw_Customer_PaymentOrders END GO Create view [dbo].Vw_Customer_PaymentOrders as select tb_ErpOrder.ID ,Ord_Number ,Ord_DividedShop ,Ord_Type ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,Ord_Class ,GP_OrderNumber ,GP_CustomerGroupID ,Cus_Name ,Cus_Name_py ,Cus_Telephone ,M_Cus_CustomerNumber ,(select stuff((select ','+ OrdPe_OrdersPerson from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPersonID ,(select stuff((select ','+dbo.fn_CheckUserIDGetUserName( OrdPe_OrdersPerson) from tb_ErpOrdersPerson where OrdPe_OrderNumber=Ord_Number for xml path('')),1,1,'')) as Ord_OrdersPerson ,Ord_CreateDatetime ,( SELECT count(id) FROM tb_ErpOrderProductList where OPlist_OrderNumber=Ord_Number and OPlist_PickupStatus=0) as PickupStatusCount from tb_ErpOrder left join tempTB_AggregationCustomer on Ord_Number=GP_OrderNumber GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords') BEGIN DROP VIEW [dbo].Vw_OrdersWagePaymentRecords END GO Create VIEW [dbo].Vw_OrdersWagePaymentRecords AS SELECT View_ErpPayment.ID ,Pay_OrdNumber ,Pay_AmountOf ,Pay_OpenSingle ,Pay_ThePayee ,Pay_PaymentMethod ,Pay_OrdersLocation ,Pay_ReceivableProject ,Pay_CustomNumber ,Pay_Remark ,convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime ,Pay_Category ,Pay_TwoPinsCategory ,Pay_UserName ,Pay_ThePayeeName ,Pay_PaymentMethodName ,Pay_TwoPinsCategoryName ,Pay_FinancialAuditdPeople ,Pay_FinancialAudit ,Pay_FinancialAuditdPeopleName ,Pay_ShootingName ,Ord_Number ,Ord_DividedShop ,Ord_Type ,Ord_Class ,Cus_Name as Ord_CustomerName1 ,Cus_Name_py ,Cus_Telephone ,(select Tsorder_Name from tb_ErpTwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name ,(select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name ,(select Tsorder_CustomerName from View_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName ,Ord_CreateDatetime ,(select OrdPe_Type from tb_ErpOrdersPerson where OrdPe_OrderNumber=Pay_OrdNumber and OrdPe_OrdersPerson=Pay_OpenSingle) as OrdPe_Type ,Ord_SeriesName ,Ord_PhotographyCategory FROM View_ErpPayment left join Vw_Customer_PaymentOrders on View_ErpPayment.Pay_OrdNumber=Vw_Customer_PaymentOrders.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpPieceCommissionRecords') BEGIN DROP VIEW [dbo].Vw_ErpPieceCommissionRecords END GO Create view [dbo].Vw_ErpPieceCommissionRecords as SELECT tb_ErpPieceCommissionRecords.ID ,Pcr_OrderNumber ,Pcr_DigitalDivision ,Pcr_Date ,Pcr_CompletionContents ,Pcr_Quantity ,Pcr_CreateTime ,Pcr_EntryPeople ,Pcr_Type ,(select [User_Name] from tb_ErpUser where Pcr_DigitalDivision=User_EmployeeID) as Pcr_DigitalDivisionName ,[dbo].[fn_GetClassCodeToName](Pcr_CompletionContents,Pcr_CompletionContents) as Pcr_CompletionContentsName ,(select [User_Name] from tb_ErpUser where Pcr_EntryPeople=User_EmployeeID) as Pcr_EntryPeopleName ,Ord_Type ,Ord_Class ,(select Cus_Name from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Name ,(select Cus_Telephone from tempTB_AggregationCustomer where Pcr_OrderNumber=GP_OrderNumber) as Cus_Telephone ,Ord_SeriesName ,Ord_SeriesPrice ,Pcr_Quantity*(select Wcs_Percentage from tb_ErpWageCommissionSet where Pcr_CompletionContents=Wcs_TypeCode) as 总价格 FROM tb_ErpPieceCommissionRecords left join tb_ErpOrder on tb_ErpPieceCommissionRecords.Pcr_OrderNumber=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpSatisfactionSurvey') BEGIN DROP VIEW [dbo].Vw_ErpSatisfactionSurvey END GO Create view [dbo].Vw_ErpSatisfactionSurvey as SELECT tb_ErpSatisfactionSurvey.ID ,Sfs_OrderNumber ,Sfs_OrderNumberDeputy ,Sfs_EmployeeID ,(select User_Name from tb_ErpUser where Sfs_EmployeeID=User_EmployeeID) as Sfs_EmployeeName ,Sfs_Type ,Sfs_SurveySetID ,Sfss_Name as Sfs_SurveySetName ,Sfs_ReturningMattersSetID ,Sfrms_Contents ,Sfs_RatingSetID ,Sfrs_Name as Sfs_RatingSetName ,Sfs_Remark ,Sfs_CreateName as Sfs_CreateNameID ,(select User_Name from tb_ErpUser where Sfs_CreateName=User_EmployeeID) as Sfs_CreateName ,Sfs_CreateTime ,Sfs_UpdateTime ,Sfs_UpdateName as Sfs_UpdateNameID ,(select User_Name from tb_ErpUser where Sfs_UpdateName=User_EmployeeID) as Sfs_UpdateName ,Cus_Name ,Cus_Name_py ,Cus_Telephone ,Sfrs_Scores ,(select count(id) from tb_ErpSatisfactionReturningMattersSet where Sfrms_SurveySetID=Sfs_SurveySetID) as SatisfactionReturningMattersSetCount FROM tb_ErpSatisfactionSurvey left join tb_ErpSatisfactionSurveySet on Sfs_SurveySetID=tb_ErpSatisfactionSurveySet.ID left join tb_ErpSatisfactionReturningMattersSet on Sfs_ReturningMattersSetID=tb_ErpSatisfactionReturningMattersSet.ID left join tb_ErpSatisfactionRatingSet on Sfs_RatingSetID=tb_ErpSatisfactionRatingSet.ID left join Vw_Customer_PaymentOrders on Sfs_OrderNumber=Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital') BEGIN DROP VIEW [dbo].Vw_OrdersWageDigital END GO Create view [dbo].Vw_OrdersWageDigital as select tb_ErpOrderDigital.Id , Ordv_Number ,Ordv_ViceNumber ,Ordv_DigitalNumber ,Ord_Number ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称 ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称 ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话 ,Ordv_ClothingName as 礼服师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师 ,Ordv_ClothingStatus as 礼服师状态 ,Ordv_ClothingTime as 选衣时间 , Ordv_FilmSelectionName as 选片师ID , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师 , Ordv_FilmSelectionStatus as 选片状态 , Ordv_FilmSelectionTime as 选片时间 , Ordv_EarlyRepairName as 初修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师 , Ordv_EarlyRepairStatus as 初修状态 , Ordv_EarlyRepairTime as 初修时间 , Ordv_RefinementName as 精修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师 , Ordv_RefinementStatus as 精修状态 , Ordv_RefinementTime as 精修时间 ,Ordv_LookDesignName as 看设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师 ,Ordv_LookDesignStatus as 看设计状态 ,Ordv_LookDesignTime as 看设计时间 ,Ordv_DesignerName as 设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师 ,Ordv_DesignerStatus as 设计状态 , Ordv_DesignerTime as 设计时间 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期 from tb_ErpOrderDigital left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePhotography') BEGIN DROP VIEW [dbo].Vw_OrdersWagePhotography END GO Create view [dbo].Vw_OrdersWagePhotography as SELECT tb_ErpOrdersPhotography.ID ,Ordpg_Number ,Ordpg_ViceNumber ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称 ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话 ,Ordpg_Sights as 拍摄名称 --,Ordpg_SightsLevel --,[dbo].[fn_GetClassCodeToName](Ordpg_SightsLevel,Ordpg_SightsLevel) as Sc_ClassName ,Ordpg_SightsType as 景点类别 ,Ordpg_ApparelQuantity as 服装套数 ,Ordpg_Photographer as 摄影师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_Photographer) as 摄影师名称 ,Ordpg_PhotographyTime as 拍摄时间 ,Ordpg_PhotographyStatus as 拍摄状态 --,[dbo].fn_CheckOrderPhotographyStatus(Ordpg_PhotographyStatus) as OrdPg_PhotographyStatusName ,Ordpg_PhotographyAssistant as 摄影助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_PhotographyAssistant) as 摄影助理名称 ,Ordpg_MakeupArtist as 化妆师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupArtist) as 化妆师名称 ,Ordpg_MakeupAssistant as 化妆助理ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_MakeupAssistant) as 化妆助理名称 ,Ordpg_BootDivision as 引导师ID ,[dbo].[fn_CheckUserIDGetUserName](Ordpg_BootDivision) as 引导师名称 --,Ordpg_ReservationPhotographyName --,Ordpg_ReservationPhotographyTime --,Ordpg_ReservationPhotographyAssistant --,Ordpg_ReservationMakeupArtist --,Ordpg_ReservationMakeupAssistant --,Ordpg_ReservationBootDivision FROM tb_ErpOrdersPhotography left join tb_ErpOrder on tb_ErpOrdersPhotography.Ordpg_Number=tb_ErpOrder.Ord_Number GO update tb_ErpSystemCategory set Sc_ClassName='提成点方案' where Sc_ClassCode='BEBBAFACDCCFBJFI' GO if not exists (select * from syscolumns where id=object_id('tb_ErpPayment') and name='Pay_Type') begin alter table tb_ErpPayment add Pay_Type int end GO if not exists (select * from syscolumns where id=object_id('tb_ErpTwoSalesOrder') and name='Tsorder_CustomerNumber') begin alter table tb_ErpTwoSalesOrder add Tsorder_CustomerNumber nvarchar(50) end GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_TwoSalesOrder') BEGIN DROP VIEW [dbo].Vw_TwoSalesOrder END GO Create view [dbo].Vw_TwoSalesOrder as SELECT dbo.tb_ErpTwoSalesOrder.ID, Tsorder_Number, Tsorder_Name, (select Cus_Name from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_CustomerName, (select Cus_Telephone from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Tsorder_Telephone, (select Cus_NamePinyin from tb_ErpCustomer where Tsorder_CustomerNumber=Cus_CustomerNumber) as Cus_NamePinyin, Tsorder_Money, Tsorder_Quantity, Tsorder_Category, Tsorder_OpenSingle, Tsorder_PersonHandling, Tsorder_Remark, Tsorder_CreateDatetime, Tsorder_UpdateDatetime, dbo.fn_CheckUserIDGetUserName(Tsorder_OpenSingle) AS [User_Name], dbo.fn_CheckUserIDGetUserName(Tsorder_PersonHandling) AS Tsorder_PersonHandlingName, dbo.fn_GetClassCodeToName(Tsorder_Category,Tsorder_Category) AS Tsorder_CategoryName, Tsorder_CustomerNumber FROM dbo.tb_ErpTwoSalesOrder GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWagePaymentRecords') BEGIN DROP VIEW [dbo].Vw_OrdersWagePaymentRecords END GO Create view [dbo].Vw_OrdersWagePaymentRecords as SELECT tb_ErpPayment.ID, Pay_OrdNumber, Pay_AmountOf, Pay_OpenSingle, Pay_ThePayee, Pay_PaymentMethod, Pay_OrdersLocation, Pay_ReceivableProject, Pay_Remark, convert(varchar(10),Pay_CreateDatetime,120) as Pay_CreateDatetime, Pay_Category, Pay_TwoPinsCategory, dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS Pay_UserName, dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS Pay_ThePayeeName, dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS Pay_PaymentMethodName, dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS Pay_TwoPinsCategoryName, Pay_FinancialAuditdPeople, Pay_FinancialAudit, dbo.fn_CheckUserIDGetUserName(Pay_FinancialAuditdPeople)AS Pay_FinancialAuditdPeopleName, Pay_ShootingName, Pay_Type, Ord_DividedShop, Ord_Type, Cus_Name as Ord_CustomerName1, (select Tsorder_Name from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_Name, (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber= Tsorder_Number) as Tsorder_CustomerName, (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) as Cus_Name, Ord_CreateDatetime, Ord_SeriesName, Ord_PhotographyCategory FROM tb_ErpPayment left join Vw_Customer_PaymentOrders on Pay_OrdNumber=Ord_Number GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_OrdersPerson') BEGIN DROP VIEW [dbo].Vw_StaffPerformance_OrdersPerson END GO create View Vw_StaffPerformance_OrdersPerson as SELECT ID ,Pay_OrdNumber as 订单号 ,Pay_ShootingName as 拍摄阶段 ,Pay_Category as 收款类别 ,Pay_TwoPinsCategory as 二销类别编号 ,dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory) AS 二销类别名称 ,Pay_AmountOf as 收款金额 ,Pay_OpenSingle as 接单人编号 , dbo.fn_CheckUserIDGetUserName(Pay_OpenSingle) AS 接单人名称 ,Pay_ThePayee as 收款人编号 ,dbo.fn_CheckUserIDGetUserName(Pay_ThePayee) AS 收款人名称 ,Pay_PaymentMethod as 付款方式编号 ,dbo.fn_GetClassCodeToName(Pay_PaymentMethod, Pay_PaymentMethod) AS 付款方式名称 ,Pay_OrdersLocation as 接单地点 ,Pay_ReceivableProject as 收款项目 ,Pay_FinancialAudit as 审核状态 ,Pay_FinancialAuditdPeople as 审核人 ,Pay_Remark as 备注 ,Pay_CreateDatetime as 收款时间 ,Pay_Type as 收款类型 ,(case Pay_Type when 0 then (select Cus_Name from tempTB_AggregationCustomer where Pay_OrdNumber=GP_OrderNumber) when 1 then (select Tsorder_CustomerName from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number) when 2 then (select Cus_Name from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) else '' end) as '客户名称' ,(case Pay_Type when 0 then (select Ord_PhotographyCategory from tb_ErpOrder where Pay_OrdNumber=Ord_Number) else '' end) as '套系类别' ,(case Pay_Type when 0 then (select Ord_SeriesName from tb_ErpOrder where Pay_OrdNumber=Ord_Number) else '' end) as '套系名称' ,(case Pay_Type when 0 then (select Ord_SeriesPrice from tb_ErpOrder where Pay_OrdNumber=Ord_Number) when 1 then (select Tsorder_Money from Vw_TwoSalesOrder where Pay_OrdNumber=Tsorder_Number) when 2 then (select Dsro_Amount from View_DressSaleRentalOrder where Pay_OrdNumber=Dsro_Number) end) as '应收金额' ,(case Pay_Type when 0 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory)) when 1 then (dbo.fn_GetClassCodeToName(Pay_TwoPinsCategory, Pay_TwoPinsCategory)) when 2 then Pay_ReceivableProject end) as '项目名称' FROM tb_ErpPayment GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_Photograph') BEGIN DROP VIEW [dbo].Vw_StaffPerformance_Photograph END GO create View Vw_StaffPerformance_Photograph as SELECT Ordv_Number as 主订单 ,Ordv_ViceNumber as 副订单 ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 拍摄名称 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number) when 1 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber) when 2 then (select max(Ordpg_PhotographyTime) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number) else '' end) as 最后拍摄时间 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) else '' end) as 未拍个数 ,(case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选' end) as 选片状态 ,Ordv_FilmSelectionTime as 选片时间 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_Photographer from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 主摄影师ID ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_Photographer) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 主摄影师名称 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_PhotographyAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 摄影助理ID ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_PhotographyAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 摄影助理名称 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_MakeupArtist from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 主化妆ID ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupArtist) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 主化妆名称 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_MakeupAssistant from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 化妆助理ID ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_MakeupAssistant) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 化妆助理名称 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ Ordpg_BootDivision from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 引导师ID ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) when 1 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber for xml path('')),1,1,'')) when 2 then (select stuff((select ','+ dbo.fn_CheckUserIDGetUserName(Ordpg_BootDivision) from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) else '' end) as 引导师名称 ,Vw_StaffPerformance_OrdersPerson.ID ,订单号 ,拍摄阶段 ,收款类别 ,二销类别编号 ,二销类别名称 ,收款金额 ,接单人编号 ,接单人名称 ,收款人编号 ,收款人名称 ,付款方式编号 ,付款方式名称 ,接单地点 ,收款项目 ,审核状态 ,审核人 ,备注 ,收款时间 ,收款类型 ,客户名称 ,套系类别 ,套系名称 ,应收金额 ,项目名称 FROM tb_ErpOrderDigital left join Vw_StaffPerformance_OrdersPerson on Ordv_Number=订单号 where 订单号 is not null GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_StaffPerformance_MemberCardRechargeRecord') BEGIN DROP VIEW [dbo].Vw_StaffPerformance_MemberCardRechargeRecord END GO create View Vw_StaffPerformance_MemberCardRechargeRecord as SELECT ID ,Mcrr_Number as 会员编号 ,Mcrr_RechargeNumber as 充值编号 ,Mcrr_RechargeName as 充值名称 ,Mcrr_RechargeAmount as 充值金额 ,Mcrr_DonateAmount as 赠送金额 ,Mcrr_DonateDiscount as 消费折扣 ,Mcrr_PaymentMethod as 支付方式编号 ,dbo.fn_GetClassCodeToName(Mcrr_PaymentMethod, Mcrr_PaymentMethod) as 支付方式名称 ,Mcrr_OrderPerson as 接单人编号 ,dbo.fn_CheckUserIDGetUserName(Mcrr_OrderPerson) AS 接单人名称 ,convert(varchar(10),Mcrr_CreateDatetime,120) as 创建时间 ,Mcrr_CreateName as 创建人编号 ,dbo.fn_CheckUserIDGetUserName(Mcrr_CreateName) AS 创建人名称 ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcrr_Number=Mc_Number)) as 客户姓名 FROM tb_ErpMemberCardRechargeRecord GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpMemberCardPayment') BEGIN DROP VIEW [dbo].Vw_ErpMemberCardPayment END GO create View Vw_ErpMemberCardPayment as SELECT ID ,Mcpt_PaymentNumber as 收款编号 ,Mcpt_Number as 会员卡编号 ,Mcpt_PaymentType as 收款类型 ,Mcpt_PaymentAmount as 收款金额 ,Mcpt_PaymentMethod as 付款方式编号 ,dbo.fn_GetClassCodeToName(Mcpt_PaymentMethod, Mcpt_PaymentMethod) as 支付方式名称 ,Mcpt_PackageClass as 服务套系类别编号 ,(case Mcpt_PackageClass when '' then (select stuff((select ','+ Mcpcd_ServiceContent from tb_ErpMemberCardPaymentContentDetail where Mcpt_PaymentNumber=Mcpcd_PaymentNumber for xml path('')),1,1,'')) else (select MscPs_PackageName from tb_ErpMemberCardServicePackageSet where Mcpt_PackageClass=MscPs_PackageNumber) end) as 服务套系类别名称 ,Mcpt_PackagePrice as 服务套系价格 ,Mcpt_Discount as 优惠折扣 ,Mcpt_OrderPerson as 接单人编号 ,dbo.fn_CheckUserIDGetUserName(Mcpt_OrderPerson) AS 接单人名称 ,Mcpt_PaymentRemark as 收款备注 ,Mcpt_FinancialAudit 财务审核状态 ,Mcpt_FinancialAuditName as 账务审核人 ,Mcpt_FinancialAuditDateTime as 财务审核时间 ,Mcpt_FinancialAuditRemark as 账务审核备注 ,convert(varchar(10),Mcpt_CreateDatetime,120) as 创建日期 ,Mcpt_CreateName as 创建人编号 ,dbo.fn_CheckUserIDGetUserName(Mcpt_CreateName) AS 创建人名称 ,(select Cus_Name from tb_ErpCustomer where Cus_CustomerNumber=(select Mc_CustomerNumber from tb_ErpMemberCard where Mcpt_Number=Mc_Number)) as 客户姓名 FROM tb_ErpMemberCardPayment GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ReportTime') BEGIN DROP VIEW [dbo].Vw_ReportTime END GO create View Vw_ReportTime as with t as( select distinct convert(varchar(10),isnull(Vw_OrdersWagePaymentRecords.Pay_CreateDatetime,View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime),120) as Pay_CreateDatetimes ,Pay_OrdNumber,Pay_CreateDatetime,Oiae_ProjectName,Oiae_IEDatetime from Vw_OrdersWagePaymentRecords full join View_ErpOtherIncomeAndExpenses on Vw_OrdersWagePaymentRecords.Pay_CreateDatetime=View_ErpOtherIncomeAndExpenses.Oiae_IEDatetime ) , t2 as( select distinct convert(varchar(10),isnull(t.Pay_CreateDatetimes,Vw_ErpMemberCardPayment.创建日期),120) as Pay_CreateDatetimes from t full join Vw_ErpMemberCardPayment on t.Pay_CreateDatetimes=Vw_ErpMemberCardPayment.创建日期 ) select distinct convert(varchar(10),isnull(t2.Pay_CreateDatetimes,Vw_StaffPerformance_MemberCardRechargeRecord.创建时间),120) as Pay_CreateDatetimes from t2 full join Vw_StaffPerformance_MemberCardRechargeRecord on t2.Pay_CreateDatetimes=Vw_StaffPerformance_MemberCardRechargeRecord.创建时间 GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_MonthlyReport') BEGIN DROP VIEW [dbo].Vw_MonthlyReport END GO create View Vw_MonthlyReport as select Pay_CreateDatetimes ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOrdersIncome , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayReplenishmentIncome ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and Pay_CreateDatetime>=Pay_CreateDatetimes and Pay_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayLateStageIncome , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherIncome ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where Mcrr_CreateDatetime>=Pay_CreateDatetimes and Mcrr_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberIncome ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and Ord_CreateDatetime>=Pay_CreateDatetimes and Ord_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayEarlyPerformance ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where Plu_CreateTime>=Pay_CreateDatetimes and Plu_CreateTime<=Pay_CreateDatetimes+' 23:59:59.000') as DayPluslatepickPerformance ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where Tsorder_CreateDatetime>=Pay_CreateDatetimes and Tsorder_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayOtherPerformance , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and Oiae_IEDatetime>=Pay_CreateDatetimes and Oiae_IEDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayExpenditure ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where Mcpt_CreateDatetime>=Pay_CreateDatetimes and Mcpt_CreateDatetime<=Pay_CreateDatetimes+' 23:59:59.000') as DayMemberCardPaymentIncome from ( select Pay_CreateDatetimes from Vw_ReportTime ) as MonthlyReport group by Pay_CreateDatetimes GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_YearReport') BEGIN DROP VIEW [dbo].Vw_YearReport END GO create View Vw_YearReport as select Pay_CreateDatetimes ,(select sum(Pay_AmountOf) from tb_ErpPayment where (Pay_Category='全款' or Pay_Category='预约收款') and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOrdersIncome , (select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='预约补款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayReplenishmentIncome ,(select sum(Pay_AmountOf) from tb_ErpPayment where Pay_Category='后期收款' and Pay_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Pay_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayLateStageIncome , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='收入' and Oiae_PaymentMethod!='BEBACCAFEGECFBJFD' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherIncome ,(select sum(Mcrr_RechargeAmount) from tb_ErpMemberCardRechargeRecord where convert(varchar,Mcrr_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberIncome ,(select sum(Ord_SeriesPrice) from tb_ErpOrder where ord_class='1' and convert(varchar,Ord_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayEarlyPerformance ,(select sum(Plu_Amount) from tb_ErpPlusPickItems where convert(varchar,Plu_CreateTime,120) like '%'+Pay_CreateDatetimes+'%') as DayPluslatepickPerformance ,(select sum(Tsorder_Money) from tb_ErpTwoSalesOrder where convert(varchar,Tsorder_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayOtherPerformance , (select sum(Oiae_Money) from tb_ErpOtherIncomeAndExpenses where Oiae_Type='支出' and convert(varchar,Oiae_IEDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayExpenditure ,(select sum(Mcpt_PaymentAmount) from tb_ErpMemberCardPayment where convert(varchar,Mcpt_CreateDatetime,120) like '%'+Pay_CreateDatetimes+'%') as DayMemberCardPaymentIncome from ( select convert(varchar(7),Pay_CreateDatetimes,120) as Pay_CreateDatetimes from Vw_ReportTime ) as YearReport group by Pay_CreateDatetimes GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ProcessStatus') BEGIN DROP VIEW [dbo].Vw_ProcessStatus END GO create View [dbo].[Vw_ProcessStatus] as Select ID ,Ordv_Number as 主订单号 ,Ordv_ViceNumber as 副订单号 ,Ordv_DigitalNumber as 拍摄次数 ,(select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类型 ,(select Ord_Class from tb_ErpOrder where Ordv_Number=Ord_Number) as 订单类别 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 1 then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber) else (select stuff((select ','+ Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number for xml path('')),1,1,'')) end) as 拍摄名称 ,(select Ord_CreateDateTime from tb_ErpOrder where Ordv_Number=Ord_Number) as 预选时间 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) else '' end) as 未拍个数 , (case Ordv_EarlyRepairStatus when 2 then 'OK' else '未修'end ) as 初修状态 , (case Ordv_FilmSelectionStatus when 1 then 'OK' else '未选'end ) as 选片状态 , (case Ordv_RefinementStatus when 2 then 'OK' else '未修'end ) as 精修状态 , (case Ordv_DesignerStatus when 2 then 'OK' else '未设计'end ) as 设计状态 , (case Ordv_LookDesignStatus when 1 then 'OK' else '未看'end ) as 看设计状态 ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_SendStatus=0) as 未发出个数 ,(select count(id) as id from tb_ErpOrderProductList where OPlist_Type=2 and OPlist_ViceNumber=Ordv_ViceNumber and OPlist_CompletedStatus=0) as 未完成个数 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 from tb_ErpOrderDigital GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_ErpCustomersTrackRecord') BEGIN DROP VIEW [dbo].Vw_ErpCustomersTrackRecord END GO create View Vw_ErpCustomersTrackRecord as SELECT id ,TR_CustomerGroupID as 客户组 ,TR_CustomerID as 客户ID ,(select Cus_Name from tb_ErpCustomer where TR_CustomerID=Cus_CustomerNumber) as 客户姓名 ,TR_TraceWay as 沟通方式 ,TR_TraceType as 沟通类型 ,TR_SpecificMatters ,TR_Communicationstatus as 沟通状态 ,TR_TraceDetailedly ,TR_CallRecording as 录音路径文件 ,TR_Remark as 备注 ,TR_TraceDateTime as 沟通日期 ,TR_TraceTimeLength as 沟通时长 ,TR_TracePersonID as 跟踪人员ID ,(select User_Name from tb_ErpUser where TR_TracePersonID=User_EmployeeID) as 跟踪人员姓名 ,TR_CreateDateTime as 创建时间 FROM dbo.tb_ErpCustomersTrackRecord GO ------ IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopEvententry]') AND type in (N'U')) begin CREATE TABLE [dbo].[tb_ErpShopEvententry]( [ID] [int] identity(1,1) primary key not null, --ID主建 [Matter_CreateName] [varchar](16) not null, --申请人 [Matter_CreateDatetime] [Datetime] not null, --申请时间 [Matter_content] [varchar](200)not null, --申请内容 [Matter_state] [varchar](10)not null, --申请状态 [Matter_UpdateName] [varchar](16)not null, --审批人 [Matter_UpdateDatetime] [Datetime], --审核时间 [Matter_opinion] [varchar](200) --审批人意见 ) EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'ID主建' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'ID' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_CreateName' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_CreateDatetime' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请内容' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_content' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'申请状态' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_state' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批人' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_UpdateName' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批时间' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_UpdateDatetime' EXEC sys.sp_addextendedproperty @name=N'Evententry', @value=N'审批人意见' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'tb_Evententry', @level2type=N'COLUMN',@level2name=N'Matter_opinion' end GO --公告表 IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopBulletin]') AND type in (N'U')) begin CREATE TABLE [dbo].[tb_ErpShopBulletin]( [ID] [int] identity(1,1) primary key not null, --ID主建 [Bulletin_issuerID] [varchar](26) not null, --发布人ID [Bulletin_announcement] [varchar](100) not null, --公告类型 [Bulletin_Title] [varchar](150)not null, --标题 [Bulletin_content] [varchar](1000)not null, --内容 [Bulletin_ReleaseTime] [Datetime] not null, --发布时间 [Bulletin_Accessory] [varchar](200) --附件位置 ) end GO IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopDesignatedAnnounced]') AND type in (N'U')) begin --指定人员查看表 CREATE TABLE [dbo].[tb_ErpShopDesignatedAnnounced]( [ID] [int] identity(1,1) primary key not null, --ID主建 [Announced_issuerID] [varchar](26) not null, --指定人员查看公告ID [Announced_announcement] [varchar](100) not null, --公告ID ) end GO IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_Shopannouncement]')) begin DROP VIEW [dbo].[View_Shopannouncement] end GO --公告与指定人员视图 Create view View_ShopAnnouncement AS select a.ID, a.Announced_issuerID, a.Announced_announcement, b.ID as 'Uid', b.Bulletin_issuerID, b.Bulletin_announcement, b.Bulletin_Title, b.Bulletin_content, b.Bulletin_ReleaseTime, b.Bulletin_Accessory from tb_ErpShopDesignatedAnnounced a Left JOIN tb_ErpShopBulletin b on a.Announced_announcement=b.ID GO --创建任务交办表 IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopAssignmente]') AND type in (N'U')) begin create table tb_ErpShopAssignmente( ID int identity(1,1) not null,--备注ID Agt_Priority int not null,--任务优先级 0 为高 1 为中 2 为低 Agt_PublishName nvarchar(20) not null,--发布人 Agt_PublishTime datetime not null,--发布时间 Agt_Content nvarchar(200) not null,--发布的任务内容 Agt_ManageName nvarchar(20) not null,--办理人 Agt_CompleteTime datetime not null,--完成时间 Agt_CompleteStatus int not null,--任务的完成状态 0 为待执行 1 为执行中 2 为已完成 3 为已搁置 4 为无法完成 5 为延后 Agt_Summary nvarchar(200) not null,--任务内容 Agt_Revert nvarchar(200) not null,--发布者的回复 Agt_CreateDatetime datetime not null,--创建的时间 Agt_CreateName nvarchar(20) not null,--创建人 Agt_UpdateDatetime datetime not null,--修改日期 Agt_UpdateName nvarchar(20) not null--修改人 ) end GO --创建任务报告表 IF not EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_ErpShopDebriefing]') AND type in (N'U')) begin create table tb_ErpShopDebriefing( Rpt_ID int identity(1,1) not null,--任务交办表关联 Rpt_CompleteState int not null,--任务的完成状态 0 为待执行 1 为执行中 2 为已完成 3 为已搁置 4 为无法完成 5 为延后 Rpt_Summary nvarchar(200) not null,--任务内容 Rpt_CreateDatetime datetime not null,--创建的时间 Rpt_UpdateName nvarchar(20) not null--修改人 ) end GO --创建视图 --按订单查询 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_OrderCustomerList]')) DROP VIEW [dbo].[Vw_OrderCustomerList] GO CREATE VIEW [Vw_OrderCustomerList] AS with t as( SELECT Plu_OrdNumber ,sum(Plu_Amount)as Plu_Amount FROM [dbo].[tb_ErpPlusPickItems] group by Plu_OrdNumber ) , t2 as( SELECT [dbo].[tb_ErpOrder].[ID] ,[Ord_Number] ,[Ord_DividedShop] ,[Ord_Type] ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH ,[Ord_Class] ,[Ord_OrderClass] ,[Ord_PhotographyCategory] ,[Ord_CustomerSource] ,[Ord_SeriesName] ,[Ord_SeriesPrice] ,[Ord_CreateDateTime] ,[Ord_CreateName] ,[Ord_UpdateDateTime] ,[Ord_UpdateName] ,t.Plu_Amount FROM [dbo].[tb_ErpOrder] left join t on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber ) select t2.* ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice ,[GP_CustomerGroupID] ,[GP_GroupType] ,[GP_CustomerType] ,[GP_CustomerStatus] ,[GP_LossReason] ,[GP_DegreeOfIntent] ,[GP_CustomerSource] ,[GP_IntroducerCustomerID] ,[GM_CustomerGroupID] ,[Cus_Name] ,[Cus_Name_py] ,[Cus_Sex_cs] ,[Cus_Telephone] ,[Cus_Region] ,[Age_String] ,[Age_Day] ,[Age_Year] ,[GregorianCalendar_Birthday] ,[GregorianCalendar_NowYearBirthday] ,[GregorianCalendar_DayForMarriage] ,[GregorianCalendar_NowYearDayForMarriage] ,[M_Cus_CustomerNumber] ,[M_Cus_Name] ,[M_Cus_Name_py] ,[M_Cus_Sex_cs] ,[M_Cus_Telephone] ,[M_Cus_MicroSignal] ,[M_Cus_QQ] ,[M_Cus_Region] ,[M_Cus_Address] ,[Ord_ViceOrderCount] ,[Mc_CradNumber] ,[Mc_CardType] from t2 left join [dbo].[tempTB_AggregationCustomer] on t2.[Ord_Number]=dbo.[tempTB_AggregationCustomer].[GP_OrderNumber] GO --按人查询 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_PersonalCustomerList]')) DROP VIEW [dbo].[Vw_PersonalCustomerList] GO CREATE VIEW [Vw_PersonalCustomerList] AS with t as( SELECT Plu_OrdNumber ,sum(Plu_Amount)as Plu_Amount FROM [dbo].[tb_ErpPlusPickItems] group by Plu_OrdNumber ) , t2 as( SELECT [dbo].[tb_ErpOrder].[ID] ,[Ord_Number] ,[Ord_DividedShop] ,[Ord_Type] ,dbo.fn_CheckOrderType([Ord_Type]) as Ord_Type_CH ,[Ord_Class] ,[Ord_OrderClass] ,[Ord_PhotographyCategory] ,[Ord_CustomerSource] ,[Ord_SeriesName] ,[Ord_SeriesPrice] ,[Ord_CreateDateTime] ,[Ord_CreateName] ,[Ord_UpdateDateTime] ,[Ord_UpdateName] ,t.Plu_Amount FROM [dbo].[tb_ErpOrder] left join t on [tb_ErpOrder].[Ord_Number]=t.Plu_OrdNumber ) select t2.* ,(isnull(t2.Plu_Amount,0)+isnull(t2.Ord_SeriesPrice,0))as yingFuPrice ,[GP_CustomerGroupID] ,[GP_GroupType] ,[GP_CustomerType] ,[GP_CustomerStatus] ,[GP_LossReason] ,[GP_DegreeOfIntent] ,[GP_CustomerSource] ,[GP_IntroducerCustomerID] ,[GP_Remark] ,[GP_BelongsPersonID] ,[GP_CreateDatetime] ,[GP_UpdateDatetime] ,[GM_CustomerGroupID] ,[GM_CustomerID] ,[GM_Master] ,[GM_ProtagonistCustomer] ,[GM_RelatedPersonID] ,[GM_Relation] ,[GM_IsOrder] ,[GM_IsOrderNumber] ,[Cus_CustomerNumber] ,[Cus_CustomizeNumber] ,[Cus_Grade] ,[Cus_Name] ,[Cus_Name_py] ,[Cus_Sex] ,[Cus_Sex_cs] ,[Cus_Birthday] ,[Cus_BirthdayLunar] ,[GregorianCalendar_Birthday] ,[GregorianCalendar_NowYearBirthday] ,[Age_Year] ,[Age_Day] ,[Age_String] ,[Cus_DayForMarriage] ,[Cus_DayForMarriageLunar] ,[GregorianCalendar_DayForMarriage] ,[GregorianCalendar_NowYearDayForMarriage] ,[Cus_QQ] ,[Cus_MicroSignal] ,[Cus_Telephone] ,[Cus_FixedPhone] ,[Cus_Region] ,[Cus_Address] ,[Cus_WorkUnit] ,[Cus_BabyWeight] ,[Cus_BornHospital] ,[Cus_Zodiac] ,[Cus_CustomerSource] ,[Cus_Status] ,[Cus_DegreeOfIntent] ,[Cus_TrackName] ,[Cus_CreateDateTime] ,[Cus_CreateName] ,[Cus_UpdateDateTime] ,[Cus_UpdateName] from t2 left join dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer on t2.[Ord_Number]=dbo.View_CustomerGroupAndCustomerGroupMembersAndErpCustomer.[GP_OrderNumber] GO IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vw_MemorialDayEmployeeList]')) DROP VIEW [dbo].[Vw_MemorialDayEmployeeList] GO CREATE VIEW [Vw_MemorialDayEmployeeList] AS SELECT [ID] ,[User_Name] ,[User_Sex] ,[User_Telephone] ,User_DateOfBirth ,dbo.Fun_GetGregorianCalendarNowYearBirthday([User_DateOfBirth],[User_BirthdayLunar]) as GregorianCalendar_NowYearBirthday FROM [dbo].[tb_ErpUser] where User_Status='在职' and len(User_DateOfBirth)>=10 and len(User_DateOfBirth)>=10 and len(User_Telephone)>=11 GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PROCE_UpdateAggregationCustomer]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer] GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: 刘超 -- Create date: 2015-07-16 -- Description: 更新聚合客户表中指定条件的客户 -- ============================================= CREATE PROCEDURE [dbo].[PROCE_UpdateAggregationCustomer] ( @WhereString varchar(2000) =N'', --条件值 为 [GP_OrderNumber]订单号,[GP_CustomerGroupID]客户组ID 字段的值 @ReturnI int output --返回更新记录数 ) AS BEGIN DECLARE @M_Cus_CustomerNumber varchar(2000) DECLARE @GP_CustomerGroupID varchar(2000) --处理开始点和结束点 delete [tempTB_AggregationCustomer] where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString) insert into [tempTB_AggregationCustomer] select * from [Vw_AggregationCustomer] where len(@WhereString)>0 and (GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString) set @ReturnI=(select count(*) from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString) ---更新group by Cus_Name,M_Cus_CustomerNumber后的客户组临时表-- set @M_Cus_CustomerNumber=(select top 1 M_Cus_CustomerNumber from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString) delete [tempTB_GroupByAggregationCustomer] where M_Cus_CustomerNumber =@M_Cus_CustomerNumber; set @GP_CustomerGroupID=(select top 1 GP_CustomerGroupID from [tempTB_AggregationCustomer] where GP_OrderNumber=@WhereString or GP_CustomerGroupID=@WhereString) delete [tempTB_GroupByAggregationCustomer] where GP_CustomerGroupID =@GP_CustomerGroupID; with t as( SELECT max(GP_CustomerGroupID) as GP_CustomerGroupID from tempTB_AggregationCustomer where M_Cus_CustomerNumber =@M_Cus_CustomerNumber group by Cus_Name,M_Cus_CustomerNumber ),t2 as( select * from tempTB_AggregationCustomer where GP_CustomerGroupID in (select GP_CustomerGroupID from t) ) insert into [tempTB_GroupByAggregationCustomer] select * from t2 ----- END GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vw_OrdersWageDigital') BEGIN DROP VIEW [dbo].Vw_OrdersWageDigital END GO create View Vw_OrdersWageDigital as select tb_ErpOrderDigital.Id , Ordv_Number ,Ordv_ViceNumber ,Ordv_DigitalNumber ,Ord_Number ,Ord_Type ,Ord_Class ,Ord_PhotographyCategory ,Ord_SeriesName ,Ord_SeriesPrice ,(case when Ord_Type = '1' then (select Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_ViceNumber = Ordv_ViceNumber) else (select top 1 Ordpg_Sights from tb_ErpOrdersPhotography where Ordpg_Number = Ord_Number) end) as 拍摄名称 ,(select Cus_Name from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户名称 ,(select Cus_Telephone from tempTB_AggregationCustomer where Ord_Number=GP_OrderNumber) as 客户电话 ,Ordv_ClothingName as 礼服师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_ClothingName) as 礼服师 ,Ordv_ClothingStatus as 礼服师状态 ,Ordv_ClothingTime as 选衣时间 , Ordv_FilmSelectionName as 选片师ID , dbo.fn_CheckUserIDGetUserName(Ordv_FilmSelectionName) as 选片师 , Ordv_FilmSelectionStatus as 选片状态 , Ordv_FilmSelectionTime as 选片时间 , Ordv_EarlyRepairName as 初修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_EarlyRepairName) as 初修师 , Ordv_EarlyRepairStatus as 初修状态 , Ordv_EarlyRepairTime as 初修时间 , Ordv_RefinementName as 精修师ID , dbo.fn_CheckUserIDGetUserName(Ordv_RefinementName)as 精修师 , Ordv_RefinementStatus as 精修状态 , Ordv_RefinementTime as 精修时间 ,Ordv_LookDesignName as 看设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_LookDesignName) as 看设计师 ,Ordv_LookDesignStatus as 看设计状态 ,Ordv_LookDesignTime as 看设计时间 ,Ordv_DesignerName as 设计师ID ,dbo.fn_CheckUserIDGetUserName(Ordv_DesignerName) as 设计师 ,Ordv_DesignerStatus as 设计状态 , Ordv_DesignerTime as 设计时间 ,(case when (select Count(*) from (select [OPlist_PickupStatus] from [tb_ErpOrderProductList] where [OPlist_ViceNumber]=Ordv_ViceNumber and OPlist_Type = '2' and [OPlist_PickupStatus] = '0') as ta)>0 then '未取' else 'OK' end) AS 取件状态 ,(select top 1 OPlist_PickupTime from tb_ErpOrderProductList where OPlist_ViceNumber = Ordv_ViceNumber and OPlist_Type = '2' and OPlist_PickupTime is not null order by OPlist_PickupTime) AS 取件日期 ,(case (select Ord_Type from tb_ErpOrder where Ordv_Number=Ord_Number) when 0 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 1 then (select count(id) as id from tb_ErpOrdersPhotography where Ordv_ViceNumber=Ordpg_ViceNumber and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) when 2 then (select count(id) as id from tb_ErpOrdersPhotography where Ordpg_Number=Ordv_Number and (Ordpg_PhotographyStatus=0 or Ordpg_PhotographyStatus=2)) else '' end) as 未拍个数 from tb_ErpOrderDigital left join tb_ErpOrder on tb_ErpOrderDigital.Ordv_Number=tb_ErpOrder.Ord_Number GO if exists(select 1 from sysobjects where id=object_id('fn_GetOrderArrears') and objectproperty(id,'IsInlineFunction')=0) BEGIN DROP function [dbo].fn_GetOrderArrears END GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderArrears]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN execute dbo.sp_executesql @statement = N'--欠款 CREATE function [dbo].[fn_GetOrderArrears](@FID varchar(800)) /****** 分类字符转换 创建人:滕工 创建日期:2014-6-23 14:55:29 修改人: 修改说明: 修改日期: ******/ Returns varchar(800) As Begin Declare @Arrears decimal(10, 2) Declare @Aoumnt decimal(10, 2) set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID) set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID) if @Aoumnt is not null begin set @Arrears = @Arrears + @Aoumnt end set @Aoumnt = 0 set @Aoumnt = (select sum(Pay_AmountOf) from dbo.tb_ErpPayment where Pay_OrdNumber =@FID) if @Aoumnt is not null begin set @Arrears = @Arrears - @Aoumnt end Return @Arrears End ' END GO if exists(select 1 from sysobjects where id=object_id('fn_GetOrderReceivable') and objectproperty(id,'IsInlineFunction')=0) BEGIN DROP function [dbo].fn_GetOrderReceivable END GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetOrderReceivable]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) BEGIN execute dbo.sp_executesql @statement = N' --应收帐款 CREATE function [dbo].[fn_GetOrderReceivable](@FID varchar(800)) /****** 分类字符转换 创建人:滕工 创建日期:2014-6-23 14:55:29 修改人: 修改说明: 修改日期: ******/ Returns varchar(800) As Begin Declare @Arrears decimal(10, 2) Declare @Aoumnt decimal(10, 2) set @Arrears = (select Ord_SeriesPrice from tb_ErpOrder where Ord_Number = @FID) set @Aoumnt = (Select sum(Plu_Amount) as Plu_Amount from tb_ErpPlusPickItems where Plu_OrdNumber = @FID) if @Aoumnt is not null begin set @Arrears = @Arrears + @Aoumnt end Return @Arrears End ' END GO IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Vwp_GetLastClientTrackRecord') BEGIN DROP VIEW [dbo].Vwp_GetLastClientTrackRecord END GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[Vwp_GetLastClientTrackRecord]')) EXEC dbo.sp_executesql @statement = N' CREATE VIEW [dbo].[Vwp_GetLastClientTrackRecord] AS SELECT id, TR_CustomerGroupID, TR_CustomerID, TR_TraceWay, TR_TraceType, TR_SpecificMatters, TR_Communicationstatus, TR_TraceDetailedly, TR_CallRecording, TR_Remark, TR_TraceDateTime, TR_TraceTimeLength, TR_TracePersonID, TR_CreateDateTime, TR_UpdateDateName FROM dbo.tb_ErpCustomersTrackRecord WHERE (id IN (SELECT MAX(id) AS Expr1 FROM dbo.tb_ErpCustomersTrackRecord AS tb_ErpCustomersTrackRecord_1 GROUP BY TR_CustomerGroupID,TR_TraceType)) ' GO --创建视图 IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_CustomerGroupMembersAndErpCustomer]')) DROP VIEW [dbo].[View_CustomerGroupMembersAndErpCustomer] GO CREATE VIEW [View_CustomerGroupMembersAndErpCustomer] AS SELECT [tb_ErpCustomerGroupMembers].[id] ,[GM_CustomerGroupID] ,[GM_CustomerID] ,[GM_Master] ,[GM_ProtagonistCustomer] ,[GM_RelatedPersonID] ,[GM_Relation] ,[GM_IsOrder] ,[GM_IsOrderNumber] ,[Cus_CustomerNumber] ,[Cus_CustomizeNumber] ,[Cus_Grade] ,[Cus_Name] ,[Cus_Name_py] ,[Cus_Sex] ,[Cus_Sex_cs] ,[Cus_Birthday] ,[Cus_BirthdayLunar] ,GregorianCalendar_Birthday ,GregorianCalendar_NowYearBirthday ,FLOOR(datediff(day,GregorianCalendar_Birthday,getdate())/365.25) as Age_Year ,DATEDIFF(day, GregorianCalendar_Birthday,Getdate()) as Age_Day ,dbo.Fun_GetAgeString(GregorianCalendar_Birthday) as Age_String ,[Cus_DayForMarriage] ,[Cus_DayForMarriageLunar] ,GregorianCalendar_DayForMarriage ,GregorianCalendar_NowYearDayForMarriage ,[Cus_QQ] ,[Cus_MicroSignal] ,[Cus_Telephone] ,[Cus_FixedPhone] ,[Cus_Region] ,[Cus_Address] ,[Cus_WorkUnit] ,[Cus_BabyWeight] ,[Cus_BornHospital] ,[Cus_Zodiac] ,[Cus_CustomerSource] ,[Cus_Status] ,[Cus_DegreeOfIntent] ,[Cus_TrackName] ,[Cus_CreateDateTime] ,[Cus_CreateName] ,[Cus_UpdateDateTime] ,[Cus_UpdateName] ,[dbo].[tb_ErpMemberCard].[Mc_CradNumber] ,[dbo].[tb_ErpMemberCard].[Mc_CardType] FROM [tb_ErpCustomerGroupMembers] left join [View_ErpCustomer] on [tb_ErpCustomerGroupMembers].[GM_CustomerID]=[View_ErpCustomer].Cus_CustomerNumber left join [dbo].[tb_ErpMemberCard] on [View_ErpCustomer].Cus_CustomerNumber=[dbo].[tb_ErpMemberCard].[Mc_CustomerNumber] GO IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[View_CustomerGroupAndCustomerGroupMembersAndErpCustomer]')) DROP VIEW [dbo].[View_CustomerGroupAndCustomerGroupMembersAndErpCustomer] GO CREATE VIEW [View_CustomerGroupAndCustomerGroupMembersAndErpCustomer] AS SELECT [tb_ErpCustomerGroup].[id] ,[GP_OrderNumber] ,[GP_CustomerGroupID] ,[GP_GroupType] ,[GP_CustomerType] ,[GP_CustomerStatus] ,[GP_LossReason] ,[GP_DegreeOfIntent] ,[GP_CustomerSource] ,[GP_IntroducerCustomerID] ,[GP_Remark] ,[GP_BelongsPersonID] ,[GP_CreateDatetime] ,[GP_UpdateDatetime] ,[GM_CustomerGroupID] ,[GM_CustomerID] ,[GM_Master] ,[GM_ProtagonistCustomer] ,[GM_RelatedPersonID] ,[GM_Relation] ,[GM_IsOrder] ,[GM_IsOrderNumber] ,[Cus_CustomerNumber] ,[Cus_CustomizeNumber] ,[Cus_Grade] ,[Cus_Name] ,[Cus_Name_py] ,[Cus_Sex] ,[Cus_Sex_cs] ,[Cus_Birthday] ,[Cus_BirthdayLunar] ,[GregorianCalendar_Birthday] ,[GregorianCalendar_NowYearBirthday] ,FLOOR(datediff(day,GregorianCalendar_Birthday,getdate())/365.25) as Age_Year ,DATEDIFF(day, GregorianCalendar_Birthday,Getdate()) as Age_Day ,dbo.Fun_GetAgeString(GregorianCalendar_Birthday) as Age_String ,[Cus_DayForMarriage] ,[Cus_DayForMarriageLunar] ,GregorianCalendar_DayForMarriage ,GregorianCalendar_NowYearDayForMarriage ,[Cus_QQ] ,[Cus_MicroSignal] ,[Cus_Telephone] ,[Cus_FixedPhone] ,[Cus_Region] ,[Cus_Address] ,[Cus_WorkUnit] ,[Cus_BabyWeight] ,[Cus_BornHospital] ,[Cus_Zodiac] ,[Cus_CustomerSource] ,[Cus_Status] ,[Cus_DegreeOfIntent] ,[Cus_TrackName] ,[Cus_CreateDateTime] ,[Cus_CreateName] ,[Cus_UpdateDateTime] ,[Cus_UpdateName] FROM [tb_ErpCustomerGroup] left join dbo.tb_ErpCustomerGroupMembers on [tb_ErpCustomerGroup].[GP_CustomerGroupID]=dbo.tb_ErpCustomerGroupMembers.[GM_CustomerGroupID] left join [dbo].[View_ErpCustomer] on dbo.tb_ErpCustomerGroupMembers.GM_CustomerID=[dbo].[View_ErpCustomer].Cus_CustomerNumber GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Fun_ConvertSex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) DROP FUNCTION [dbo].[Fun_ConvertSex] GO CREATE FUNCTION dbo.Fun_ConvertSex( @value int --性别值 ) /****** 转换性别 创建人:刘超 创建日期:2015-6-11 14:10 修改人: 修改说明: 修改日期: ******/ RETURNS nvarchar(10) AS BEGIN DECLARE @ret nvarchar(10) SET @ret = '男' if @value=0 SELECT @ret = '男' else SELECT @ret = '女' Return @ret END GO