我是一名新手开发人员,但我当然知道曾经编写的脚本应该具有某种特定的行为,但是在以下用例中,这显然没有发生。
我用INSERT INTO SELECT语句创建了一个脚本,该脚本应该过滤出重复项并将差异放入STAGING表中,并在STAGING2表中保留过去7天的记录。我在后端运行SQL作业,以确保我的脚本每隔几分钟运行一次。现在,一次又一次发生的怪异事情是作业保持正常运行,正确填充了我的FACT表,没有重复项,但是突然之间JOBS开始失败,因为某种程度上重复项进入了系统。如果有人可以帮助,我将分享以下代码。 (这是已经使用了几个月的相同代码)。
USE [PowerBI]
GO
/****** Object: StoredProcedure [ALJAZEERA\Naeemf].[sp_fact_ticket] Script Date: 11/4/2018 1:44:59 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [ALJAZEERA\Naeemf].[sp_fact_ticket]
AS
BEGIN
truncate table fact.ticket
insert into fact.ticket
select
[ticket_type],
[Assigned_to],
[caller],
[Due_Date],
[Ticket_Number],
[active],
[Approval_History],
[Duration_Seconds],
[Assigned to],
[Email Address (Assigned to)],
[Assignment Group],
[Business_Duration],
[Closed By Email Address],
[Link],
[Location],
[Made_SLA],
[Opened By Full Name],
[Opened By Email Address],
[Opened at date],
[Reassignment_Count],
[Service_Offering],
[Short_Description],
[State Name],
[u_Type],
[Created On Date],
[u_Comments_Updated],
[u_One_To_One_Training],
[u_Priority_Changed],
[Vendor],
[Vendor_Number],
[Caller Primary Group],
[Opened By Primary Group],
[Closed By Primary Group],
[Category],
[CMDB_CI],
[Opened By Job Title],
[Opened Month Name],
[Opened Year],
[Opened at Day Name],
[Opened Quarter],
[Closed at year],
[Closed at month name],
[Closed at Date],
[Closed at quarter],
[Contact_Type],
[Sharepoint_Request],
[SD_Request],
[Priority Name],
[Assigned to Primary Group],
[closed by],
[Sys_ID],
[u_Confidential],
[close_notes],
[u_bomgar]
from
(
select 'Incident' as ticket_type, [assigned to] AS Assigned_to,[Caller ID Name] AS caller, number AS Ticket_Number,active as active,[Approval_History],Calendar_STC as Duration_Seconds,[Assigned to],[Email Address (Assigned to)],[Assignment Group],
Business_Duration,[Closed By Email Address],Due_Date,Link,[Location],Made_SLA,[Opened By Full Name],[Opened By Email Address],[Opened at date],Reassignment_Count,Service_Offering,Short_Description,[State Name],u_Type,[Created On Date],u_Comments_Updated,
[u_One_To_One_Training],u_Priority_Changed,u_Vendor as Vendor,u_Vendor_Number as Vendor_Number,[Caller Primary Group],[Opened By Primary Group],[Closed By Primary Group],Category,CMDB_CI,[Opened By Job Title],[Opened Month Name],[Opened Year],[Opened at date] as OD1,[Opened at Day Name],
[Opened Quarter],[Closed at year],[Closed at month name],[Closed at Date],[Closed at quarter],Contact_Type,null as Sharepoint_Request,null as SD_Request,[Priority Name],[Assigned to Primary Group],[closed by],[Sys_ID],u_confidential,
close_notes,[u_bomgar]
from [ALJAZEERA\Naeemf].[Incidents Hierarchy View]
UNION
select 'Task', [assigned to], NULL, number,active,approval,calendar_stc,[Assigned To],[Assigned to Email],[Assignment Group],business_duration,[Closed By Email],due_date,Link,[Location],made_sla,[Opened By],[Opened By Email],opened_at,reassignment_count,[business_service],short_description,[State],sys_class_name,[opened_at],u_comments_updated,
u_one_to_one_training,u_priority_changed,u_vendor,u_vendor_number,null,[Opened By Primary Group],[Closed By Primary Group],u_first_category,[CMDB CI],[Opened By Title],[Opened at Month Name],[Opened at Year],opened_at,[Opened at Day Name],
[Opened at Quarter],[Closed at year],[Closed at Month Name],[Closed At],[Closed at Quarter],null,null,null,[Priority],[Assigned To Primary Group],[closed by name],null,u_confidential,close_notes,u_bomgar
from [ALJAZEERA\Naeemf].[Catalog Tasks Hierarchy View]
Union
select 'Request', null,null,number,active,approval,calendar_stc,[Assigned to],[Assigned to email],[Assignment Group],business_duration,[Closed By Email],due_date,link,[Location],made_sla,[Opened By],[Opened By Email],opened_at,reassignment_count,Service_Offering,short_description,request_state,sys_class_name,sys_created_on,u_comments_updated,
u_one_to_one_training,u_priority_changed,u_vendor,u_vendor_number,null, [Opened By Primary Group],[Closed By Primary Group],null,CMDB_CI,[Opened By Title],[Opened Month Name],[Opened Year],opened_at,[Opened WeekdayName],[Opened Quarter]
,[Closed Year],[Closed Month Name],closed_at,[Closed Quarter],contact_type,u_sharepoint_request,u_sd_request,null,null,[closed by],[sys_id],null,close_notes,null
from [ALJAZEERA\Naeemf].[Requests Hierarchy View]
Union
select 'Change',[assigned to],null,number,active,[approval_history],null,[Assigned To],[Assigned to Email],[Assignment Group],[business_duration],[Closed by Email],[due_date],null,[location],
[made_sla],[Opened By],[Opened By Email],[opened_at],[reassignment_count],[Service Offering],[short_description],[State],null,null,[u_comments_updated],[u_one_to_one_training],[u_priority_changed],
[u_vendor],[u_vendor_number],null,[Opened By Primary Group],[Closed by Primary Group],[category],[CMDB_CI],[Opened By Title],[Opened Month Name],[Opened Year],[opened_at] as OD1,null,
[Opened Quarter],[Closed Year],[Closed Month Name],[closed_at],[Closed Quarter],null,null,null,null,[Assigned to Primary Group],[Closed By],[sys_id],u_confidential,close_notes,null
from dbo.Fact_Change
Union
select 'Problem',[Assigned to],null,number,active,approval,null,[Assigned to],[Assigned to Email],[Assignment Group],business_duration,[Closed By Email],due_date,link,Null,made_sla,[Opened By],null,[Created Date],reassignment_count,Service_Offering,short_description,[state],sys_class_name,[Created Date],u_comments_updated,
u_one_to_one_training,u_priority_changed,u_vendor,u_vendor_number,null,null,null,u_category,CMDB_CI,[Opened By Title],[Created Month Name],[Created Year],[Created Date],[Created Day Name],[Created Quarter],[Closed Year],[Closed Month Name],[Closed at Date],
[Closed Quarter],null,null,null,[Priority],null,[closed by],[sys_id],u_confidential,close_notes,null
from [ALJAZEERA\Naeemf].[Problems Hierarchy View]) a
END
感谢我所能获得的所有帮助。
谢谢。
答案 0 :(得分:0)
查询是否在没有过程本身的情况下运行?
查看各种并集,就好像您交叉了具有不同数据类型/ null的列。如果表结构已更改,从而阻止为其中一列输入null,则这也可能导致您遇到问题。
尝试从该过程中删除查询,看看是否有任何结果/得到的结果。