Some reason I am stuck on this one.
Select Count(InspectionID) as NumberOfDupes,[Date],Location,PermitID,Inspector,[Type]
From Inspections
Where NumberOfDupes > 1 and Deleted <> 1
Group By [Date],Location,PermitID,Inspector,[Type]
Order By [Date], NumberOfDupes, Location, PermitID
and I get...
Msg 207, Level 16, State 1, Line 3
Invalid column name 'NumberOfDupes'.
I need to get a report of all duplicates. If there is only one occurrence then it is not a duplicate.
Table Structure...
CREATE TABLE [dbo].[Inspections] (
[InspectionID] int IDENTITY(1, 1) NOT NULL,
[Location] int NOT NULL,
[Date] datetime CONSTRAINT [DF_Inspections_Date] DEFAULT getdate() NOT NULL,
[Inspector] int NOT NULL,
[Travel] float CONSTRAINT [DF_Inspections_Travel] DEFAULT 0 NOT NULL,
[Time] float CONSTRAINT [DF_Inspections_Time] DEFAULT 0 NOT NULL,
[Type] int CONSTRAINT [DF_Inspections_Type] DEFAULT 1 NOT NULL,
[Violations] bit CONSTRAINT [DF_Inspections_Green] DEFAULT 0 NOT NULL,
[CorrectedOnDate] datetime NULL,
[CorrectedByDate] datetime NULL,
[NumberOfViolations] int DEFAULT 0 NULL,
[Mileage] float NULL,
[ReinspectionDate] datetime NULL,
[PermitID] int DEFAULT 0 NULL,
[PermitTypeID] int DEFAULT 0 NULL,
[Comments] varchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Deleted] bit DEFAULT 0 NULL,
[Passed] bit DEFAULT 0 NULL,
[Finaled] bit DEFAULT 0 NULL,
[LifeSafetyViolations] int DEFAULT 0 NULL,
[FireProtSysViolations] int DEFAULT 0 NULL,
[MinorViolations] int DEFAULT 0 NULL,
[SqrFootage] int DEFAULT 0 NULL,
[NewNotSynced] bit DEFAULT 0 NULL,
[AdminViolations] int DEFAULT 0 NULL,
[ModifiedOn] datetime NULL,
[ReInspectionFee] float NULL,
[LifeSafetyCorrectedBy] datetime NULL,
[FireProtSysCorrectedBy] datetime NULL,
[MinorCorrectedBy] datetime NULL,
[AdminCorrectedBy] datetime NULL,
[LifeSafetyCorrectedOn] datetime NULL,
[FireProtSysCorrectedOn] datetime NULL,
[MinorCorrectedOn] datetime NULL,
[AdminCorrectedOn] datetime NULL,
[RealMiles] float DEFAULT 0 NULL,
[RealTime] float DEFAULT 0 NULL,
[RealTravel] float DEFAULT 0 NULL,
[AHJID] int DEFAULT 0 NULL,
[FireProtViolationCorrected] int DEFAULT 0 NULL,
[HazardsCorrected] int DEFAULT 0 NULL,
[IsReinspection] bit DEFAULT 0 NULL,
[InspectionFee] money DEFAULT 0 NULL,
[ConstructionViolationCorrectedOn] datetime NULL,
[NumberOfCorrected] int DEFAULT 0 NULL,
[FireProtViolationOutstanding] int DEFAULT 0 NULL,
[HazardsOutstanding] int DEFAULT 0 NULL,
[NumberOfOutstanding] int DEFAULT 0 NULL,
[AveragedRealNumbers] bit DEFAULT 0 NULL,
[CTReportId] int NULL,
CONSTRAINT [PK_Inspections] PRIMARY KEY CLUSTERED ([InspectionID])
WITH (
PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
ON [PRIMARY]
GO
EXEC sp_addextendedproperty 'MS_Description', N'FID Number', N'schema', N'dbo', N'table', N'Inspections', N'column', N'Location'
GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[Inspections_triu] ON [dbo].[Inspections]
WITH EXECUTE AS CALLER
FOR INSERT, UPDATE
AS
BEGIN
/* Trigger body */
IF @@ROWCOUNT=0 RETURN
UPDATE U SET ModifiedOn = GETDATE()
FROM INSPECTIONS U INNER JOIN INSERTED I ON U.InspectionId = I.InspectionId
END
GO
Select Count(InspectionID) as NumberOfDupes,[Date],Location,PermitID,Inspector,[Type]
From Inspections
Where NumberOfDupes > 1 and Deleted <> 1
Group By [Date],Location,PermitID,Inspector,[Type]
Order By [Date], NumberOfDupes, Location, PermitID
and I get...
Msg 207, Level 16, State 1, Line 3
Invalid column name 'NumberOfDupes'.
I need to get a report of all duplicates. If there is only one occurrence then it is not a duplicate.
Table Structure...
CREATE TABLE [dbo].[Inspections] (
[InspectionID] int IDENTITY(1, 1) NOT NULL,
[Location] int NOT NULL,
[Date] datetime CONSTRAINT [DF_Inspections_Date] DEFAULT getdate() NOT NULL,
[Inspector] int NOT NULL,
[Travel] float CONSTRAINT [DF_Inspections_Travel] DEFAULT 0 NOT NULL,
[Time] float CONSTRAINT [DF_Inspections_Time] DEFAULT 0 NOT NULL,
[Type] int CONSTRAINT [DF_Inspections_Type] DEFAULT 1 NOT NULL,
[Violations] bit CONSTRAINT [DF_Inspections_Green] DEFAULT 0 NOT NULL,
[CorrectedOnDate] datetime NULL,
[CorrectedByDate] datetime NULL,
[NumberOfViolations] int DEFAULT 0 NULL,
[Mileage] float NULL,
[ReinspectionDate] datetime NULL,
[PermitID] int DEFAULT 0 NULL,
[PermitTypeID] int DEFAULT 0 NULL,
[Comments] varchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Deleted] bit DEFAULT 0 NULL,
[Passed] bit DEFAULT 0 NULL,
[Finaled] bit DEFAULT 0 NULL,
[LifeSafetyViolations] int DEFAULT 0 NULL,
[FireProtSysViolations] int DEFAULT 0 NULL,
[MinorViolations] int DEFAULT 0 NULL,
[SqrFootage] int DEFAULT 0 NULL,
[NewNotSynced] bit DEFAULT 0 NULL,
[AdminViolations] int DEFAULT 0 NULL,
[ModifiedOn] datetime NULL,
[ReInspectionFee] float NULL,
[LifeSafetyCorrectedBy] datetime NULL,
[FireProtSysCorrectedBy] datetime NULL,
[MinorCorrectedBy] datetime NULL,
[AdminCorrectedBy] datetime NULL,
[LifeSafetyCorrectedOn] datetime NULL,
[FireProtSysCorrectedOn] datetime NULL,
[MinorCorrectedOn] datetime NULL,
[AdminCorrectedOn] datetime NULL,
[RealMiles] float DEFAULT 0 NULL,
[RealTime] float DEFAULT 0 NULL,
[RealTravel] float DEFAULT 0 NULL,
[AHJID] int DEFAULT 0 NULL,
[FireProtViolationCorrected] int DEFAULT 0 NULL,
[HazardsCorrected] int DEFAULT 0 NULL,
[IsReinspection] bit DEFAULT 0 NULL,
[InspectionFee] money DEFAULT 0 NULL,
[ConstructionViolationCorrectedOn] datetime NULL,
[NumberOfCorrected] int DEFAULT 0 NULL,
[FireProtViolationOutstanding] int DEFAULT 0 NULL,
[HazardsOutstanding] int DEFAULT 0 NULL,
[NumberOfOutstanding] int DEFAULT 0 NULL,
[AveragedRealNumbers] bit DEFAULT 0 NULL,
[CTReportId] int NULL,
CONSTRAINT [PK_Inspections] PRIMARY KEY CLUSTERED ([InspectionID])
WITH (
PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)
ON [PRIMARY]
GO
EXEC sp_addextendedproperty 'MS_Description', N'FID Number', N'schema', N'dbo', N'table', N'Inspections', N'column', N'Location'
GO
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[Inspections_triu] ON [dbo].[Inspections]
WITH EXECUTE AS CALLER
FOR INSERT, UPDATE
AS
BEGIN
/* Trigger body */
IF @@ROWCOUNT=0 RETURN
UPDATE U SET ModifiedOn = GETDATE()
FROM INSPECTIONS U INNER JOIN INSERTED I ON U.InspectionId = I.InspectionId
END
GO