I am trying to put the results of a SQL query into a table in a report but I am getting an error. The system thinks the the query is an update query. Is there a way to force it to think it is a Select query?
The code works in SQL Server Management Studio.
I have tried creating a Stored Procedure and get the same error.
SQL Query
declare @Previous_2_Days date
declare @Start_Time varchar(Max)
declare @End_Time varchar(Max)
declare @Previous_day_date date
declare @Third_Shift_Start varchar(Max)
declare @Third_Shift_End varchar(Max)
Set @Start_Time = '18:30:00.000'
Set @End_Time = '05:29:59.999'
Set @Previous_2_Days = (SELECT Convert(date, dateadd(day,datediff(day,2,GETDATE()),0)));
Set @Previous_day_date = (SELECT Convert(date, dateadd(day,datediff(day,1,GETDATE()),0)));
Set @Third_Shift_Start = '' + convert(varchar, @Previous_2_Days) + ' ' + @Start_Time + ''
Set @Third_Shift_End = '' + convert(varchar, @Previous_day_date) + ' ' + @End_Time + ''
If Exists
(
Select QR_Code as 'QR Code', Count(QR_Code) as 'Number of Duplicates'
From Laser_Marker_Success_Rate
Where DT_stamp Between @Third_Shift_Start and @Third_Shift_End
Group by QR_Code
Having Count(QR_Code) > 1
)
Begin
Select QR_Code as 'QR Code', Count(QR_Code) as 'Number of Duplicates'
From Laser_Marker_Success_Rate
Where DT_stamp Between @Third_Shift_Start and @Third_Shift_End
Group by QR_Code
Having Count(QR_Code) > 1
End
Else
Select 'No Duplicates Codes' as 'QR Code', 'Number of Duplicates' = 0
System Info.
Ignition version - Version: 7.9.5
OS - Windows Server 2012 R2