SQL Server - Previous day data retrieval + conditions

Hi Guys,
I am retrieving data from a view for a dashboard and I need some help with my query to retrieve yesterday's data where the following conditions meet:
When 'Monday' retrieve JUST friday's data. When 'Tuesday' retrieve data from Saturday until Monday, When 'other days' JUST retrieve previous day,
But there is another condition: Exclude 'previous day' data WHERE "DESP_PostedDate..." column is empty. (as this will skew the percentages)
This is what I have so far:
SELECT CORD_DocumentCode
,OpenDate
,datedue
,DESP_PostedDate
,COUNT(CORD_DocumentCode) AS Order_Count
,SUM(CASE WHEN InFullAndOneTime = 2 THEN 1 ELSE 0 END) AS Difot_count
,SUM(CASE WHEN InFullAndOneTime = 2 THEN 1 ELSE 0 END) * 1.0 /COUNT(CORD_DocumentCode) AS DIFOT
FROM DIFOTIS_View
WHERE (OpenDate >= CASE
WHEN DATENAME(dw, CONVERT(CHAR(8), GETDATE(), 112)) LIKE 'Monday' THEN CONVERT(CHAR(8), DATEADD(dd, - 2, GETDATE()), 112)
WHEN DATENAME(dw, CONVERT(CHAR(8), GETDATE(), 112)) LIKE 'Tuesday' THEN CONVERT(CHAR(8), DATEADD(dd, - 3, GETDATE()), 112) ELSE CONVERT(CHAR(8),
DATEADD(dd, - 1, GETDATE()), 112) END) GETDATE(), 112))
GROUP BY OpenDate
,CORD_DocumentCode
,datedue
,DESP_PostedDate
ORDER BY OpenDate
This will show you last week's date from "Wednesday" and the result is 15.4 % (or 4/26) whereas I would like it to show 80% (or 4 / 5)
I have tried adding
((Datediff(day,Opendate,getdate())=1) and DESP_PostedDate is not null)
but it shows then ONLY data from the previous day.
What do you suggest I should do? Please find below Data from friday for your perusal.
All help is appreciated. Thanks
Eric
CORD_DocumentCode OpenDate datedue DESP_PostedDate Order_Count Difot_count DIFOT
CASW92195 2014-10-19 2014-10-19 2014-10-20 1 1 1.000000000000
CASW92196 2014-10-19 2014-10-19 2014-10-20 1 1 1.000000000000
CASW92197 2014-10-19 2014-10-19 2014-10-20 1 1 1.000000000000
CASW92198 2014-10-19 2014-10-19 2014-10-20 1 1 1.000000000000
CASW92199 2014-10-19 2014-10-19 2014-10-20 1 1 1.000000000000
CASW92200 2014-10-19 2014-10-19 NULL 1 0 0.000000000000
CASW92201 2014-10-20 2014-10-20 2014-10-20 1 1 1.000000000000
CASW92202 2014-10-20 2014-10-20 2014-10-20 1 1 1.000000000000
CASW92203 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CASW92204 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CASW92205 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CASW92206 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CORD37188 2014-10-20 2014-10-20 NULL 1 0 0.000000000000
CORD37189 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37190 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37191 2014-10-20 2014-10-20 2014-10-21 1 0 0.000000000000
CORD37192 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37193 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37195 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37196 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37197 2014-10-20 2014-10-20 2014-10-21 1 0 0.000000000000
CORD37198 2014-10-20 2014-10-20 2014-10-21 1 0 0.000000000000
CORD37199 2014-10-20 2014-10-20 2014-10-20 1 0 0.000000000000
CORD37200 2014-10-20 2014-10-20 NULL 1 0 0.000000000000
CORD37211 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CORD37216 2014-10-20 2014-10-20 2014-10-21 1 1 1.000000000000
CASW92207 2014-10-21 2014-10-21 2014-10-21 1 1 1.000000000000
CASW92208 2014-10-21 2014-10-21 2014-10-21 1 1 1.000000000000
CASW92209 2014-10-21 2014-10-21 2014-10-21 1 1 1.000000000000
CASW92210 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CASW92211 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CASW92212 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CASW92213 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37218 2014-10-21 2014-10-21 2014-10-21 1 1 1.000000000000
CORD37220 2014-10-21 2014-10-20 2014-10-21 1 0 0.000000000000
CORD37221 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37222 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37225 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37227 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37228 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37229 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37230 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37231 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37232 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37233 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37234 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37235 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37236 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37237 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37238 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37239 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
CORD37241 2014-10-21 2014-10-21 NULL 1 0 0.000000000000
Thanks
Eric

Hi Eric,
Pleas try below code ,Hope this help you
As per My understanding you were looking for below logic
If Monday --> Friday only
 Tuesday --> Saturday,sunday, Monday
Rest Days-->only Preovious Day
plus additional rule desp_posted date is null then exclude yestreday's data.
/*Main Query */
declare @ReportDate datetime
set @ReportDate='2014-10-22 00:00:00.000'
select
OpenDate,cast(datepart(dw,OpenDate) as varchar),DESP_PostedDate
from base
where cast(datepart(dw,OpenDate) as varchar)
in ( SELECT * FROM dbo.CSVToTable(
case
when datepart(dw,@ReportDate) =7 then '6'
when datepart(dw,@ReportDate) =6 then '5'
when datepart(dw,@ReportDate) =5 then '4'
when datepart(dw,@ReportDate) =4 then '3'
when datepart(dw,@ReportDate) =2 then '6'
when datepart(dw,@ReportDate) =3 and DESP_PostedDate is not null then '7,1,2'
when datepart(dw,@ReportDate) =3 and DESP_PostedDate is null then '7,1'
when datepart(dw,@ReportDate) =1 then '7' Else NULL END )) and opendate>=DATEADD(day, -7,@ReportDate)
/* Table Creation & Sample data */
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[CSVToTable] (@InStr VARCHAR(MAX))
RETURNS @TempTab TABLE
(id int not null)
AS
BEGIN
;-- Ensure input ends with comma
SET @InStr = REPLACE(@InStr + ',', ',,', ',')
DECLARE @SP INT
DECLARE @VALUE VARCHAR(1000)
WHILE PATINDEX('%,%', @INSTR ) <> 0
BEGIN
SELECT @SP = PATINDEX('%,%',@INSTR)
SELECT @VALUE = LEFT(@INSTR , @SP - 1)
SELECT @INSTR = STUFF(@INSTR, 1, @SP, '')
INSERT INTO @TempTab(id) VALUES (@VALUE)
END
RETURN
END
GO
/****** Object: Table [dbo].[base] Script Date: 10/28/2014 6:07:17 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[base](
[CORD_DocumentCode] [varchar](50) NULL,
[OpenDate] [datetime] NULL,
[datedue] [datetime] NULL,
[DESP_PostedDate] [datetime] NULL,
[Order_Count] [int] NULL,
[Difot_count] [int] NULL,
[DIFOT] [numeric](18, 2) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING ON
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92195', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92196', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92197', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92198', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92199', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92200', CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3C900000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92201', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92202', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92203', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92204', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92205', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92206', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37188', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37189', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37190', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37191', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37192', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37193', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37195', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37196', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37197', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37198', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37199', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37200', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37211', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37216', CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92207', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92208', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92209', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92210', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92211', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92212', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CASW92213', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37218', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37220', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CA00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37221', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37222', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37225', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37227', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37228', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37229', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37230', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37231', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37232', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37233', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37234', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37235', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37236', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37237', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37238', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37239', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37241', CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37985', CAST(0x0000A3C800000000 AS DateTime), CAST(0x0000A3C800000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 2, 0, CAST(1.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD379865', CAST(0x0000A3C700000000 AS DateTime), CAST(0x0000A3C700000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 1, CAST(3.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37875', CAST(0x0000A3C600000000 AS DateTime), CAST(0x0000A3C600000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37241', CAST(0x0000A3C500000000 AS DateTime), CAST(0x0000A3C500000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 1, 0, CAST(0.00 AS Numeric(18, 2)))
GO
INSERT [dbo].[base] ([CORD_DocumentCode], [OpenDate], [datedue], [DESP_PostedDate], [Order_Count], [Difot_count], [DIFOT]) VALUES (N'CORD37263', CAST(0x0000A3C400000000 AS DateTime), CAST(0x0000A3C500000000 AS DateTime), CAST(0x0000A3CB00000000 AS DateTime), 2, 0, CAST(3.00 AS Numeric(18, 2)))
GO
Shiv
please mark as Answer if helpfull

Similar Messages

  • Java program to watch sql server for new data

    I need to write a java program to watch a ms sql server database table, whenever there are data inserted into this table, I need to followup with some functions!
    I have done some jsp work before, but writing a java process that would do watch, i have no idea. any help?
    thankx
    ku

    The only efficient mechanism I can imagine would be to define a trigger on insert and/or update on the table and have this do something (not sure what, don't use MS SQL Server these days).
    Chuck

  • How to get previous day data if i dont have current day data.

    Hello Gurus,
    I have a stock levels data in ODS. when there is no movements, we are not getting any stocks into ODS. So we have to get previous day data as it is for current day data into another ODS.
    Could you please help me in this regard.
    Thanks in advance,
    Rama

    Rama -    
            0CALDAY can't help us in this scenario .
    Step 1 :
        To do this - You have to add one ZDATE (InfoObject ) to 1st ODS. ZDATE is updated by itself from current date of system  when ever you are loading data to 1st ODS.
    Step 2:
       You have to do full update to 2nd ods.At the selection screen of InfoPackage  (from 1st ODS to 2nd ODS ) you have to write following code for ZDATE.
    pseudo Code:
    1) Select fields "Rec_INSERT","Time stamp","Request Status" and "Request ID"  where ICUBE = ODS1 from table "RSMONICDP"
    2) Populate above selected fields data in INTERNAL TABLE
    3) Sort INTERNAL TABLE by Time stamp .
    4)
         If (Record Count = ' 0 ' for current date in internal table )
         update records from  ODS1 to ODS2 where ZDATE = "yesterday date"
         else
         update records from ODS1 to ODS2 where ZDATE= "today date"
         endif.
    Make sure this is full update not delta update from ODS1 to ODS2
    I am sorry, I m not good in Coding but I am sure if  u use this logic,You can meet your requirement.
    I hope you can understand my logic. Let me know if you have any questions,
    Anesh B .

  • [Oracle][ODBC SQL Server Driver]String data, right truncation {01004}

    While importing data from SQL Server 2005 to Oracle gateway 11g Release2, i am getting following error:
    insert into CSDescr select * from CSDescr@sqlserver
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    +[Oracle][ODBC SQL Server Driver]String data, right truncation {01004}+
    ORA-02063: preceding 2 lines from SQLSERVER
    Oracle database characterset is AL32UTF8
    SQLServer database characterset is SQL_Latin1_General_CP1_CI_AS
    Following is the configuration in the parameter file for gateway:
    HS_KEEP_REMOTE_COLUMN_SIZE=LOCAL
    HS_NLS_LENGTH_SEMANTICS=CHAR
    I think setting the HS_LANGUAGE parameter shall fix the error but I  want to know what should be the value of this parameter?

    HS_LANGUAGE needs to be set to a character set that is used by the foreign database
    So try: HS_LANGUAGE=american_america.WE8MSWIN1252
    Also specify HS_NLS_NCHAR=UCS2 as the nvarchars of a SQl Server are stored in UCS2 character set

  • SQL Server 2012 Change Data Capture for Oracle by Attunity support for Oracle 12

    I would like to know if there are any plans for SQL Server 2012 Change Data Capture for Oracle by Attunity to support versions of Oracle 12 and if by when.

    I have asked from the author of
    http://blogs.msdn.com/b/mattm/archive/2012/03/26/cdc-for-oracle-in-sql-server-2012.aspx about this.
    I will either ask him to answer here or I would be a messenger.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • Importing SQL Server Schema and Data

    What is the best way to go about importing schema objects (tables, contstraints, triggers, stored procs, etc.) and data from SQL Server to Oracle?

    No offence taken :)
    But I have copied data from SQL Server DB to Oracle using SQL Server Enterprise manager Data transformation services.
    About 30 tables with summary amount a few hundred thousand rows (~300K) took about 1.5 hour.
    Did it several times when tested and run for production in a data conversion project. Of course when copied to Oracle all data was processed to adapt for our new data model, but that is another story.
    It was quick and easy solution. OK if one needs to copy at least a few M rows then probably he needs to look for different tools.
    Gints Plivna
    http://www.gplivna.eu

  • Previous days data based on passing parameter and date

    Hi,
    i have one rek..that requirement to to show the previous days data based on the number passing to the parameter parameter.
    lets suppose if user enters the date '25 Mar 2012 in one dashboard prompt and in another prompt user enters the no.of days(Ex: 5).then report should display the last 5 days data i.e 25 mar 2012,24 mar 2012,23 mar 2012,22 mar 2012,21 mar 2012.
    can anybody tell me how can i achieve this..
    Thanks in advance...

    user12255470 wrote:
    Hi,
    i have one rek..that requirement to to show the previous days data based on the number passing to the parameter parameter.
    lets suppose if user enters the date '25 Mar 2012 in one dashboard prompt and in another prompt user enters the no.of days(Ex: 5).then report should display the last 5 days data i.e 25 mar 2012,24 mar 2012,23 mar 2012,22 mar 2012,21 mar 2012.
    can anybody tell me how can i achieve this..
    Thanks in advance...Read the article and adapt it to what you are doing. It's very similar...
    http://oraclebizint.wordpress.com/2008/03/11/oracle-bi-ee-101332-rolling-yearmonth-and-date-filters-moving-window-filters/

  • SQL Server PDW(Parallel Data Warehouse)

    Dear,
    There are several features which are unsupported at SQL Server PDW(Parallel Data Warehouse) version.
    Such as
    UDF(User Defined Function) / Extended Stored Procedure, CLR / Cursor / Trigger /
    @@SPID, @@SNAME_SUSER so on.
    I'm wondering when these features will be supported.
    Would you let me know approximate target date or road map?
    Thanks, Jungwon

    As far as I can tell , these features do not exist because the appliance purpose is to limit any components that can introduce a chance of performance degradation such as CLR and extended stored procedures beside also focusing on the core features for now.
     The word in the street is you have have your own CLR code in a business layer while PDW is for mass data analytics.
    for something like @@SPID , you should use the management web console & DMVs where they provides more rich information
    HTH
    Please click Vote As Helpful , Propose As Answer and/or Mark As Answer
    if you think this post helps!

  • Hyperion11.1.2.2 Sql Server and Essbase data load error

    Gentlemen,
    i have issue on loading data in Essbase via sql server , while loading data it was fine and all of sudden i see that i get network error 10054
    network error 10054 failed to recive data / send data
    unexpected essbase error 1042013
    even when i try to load manully it says Data Load Fails error Data load buffer [9999] does not exist Unexpected Essbase error 1270040
    and in logs
    Received client request: MaxL: Execute (from user [admin@Native Directory
    *Error writing to server*
    Also tried with maxll its the same issue
    is .esm is loacked?
    any issue with ODBC?
    or any orphan link which is connected to sql  and hyperion unable to process another ?
    let me know your thoughts
    thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Can you try limiting the query to return some records? Try adding a where clause and see whether that works?
    Regards
    Celvin
    http://www.orahyplabs.com

  • OBIEE reverse engineering to go from SQL Server to a data warehouse

    Hi,
    I'm new to data modeling for warehouses. We currently have an OBIEE environment set up where the data source was SQL Server transactional tables. The SQL Server data is to be moved to a non-Oracle data warehouse and I need to produce a logical data model for the warehouse folks at my company. Unfortunately, the SQL Server data was never modeled, so, I'm basing the model from the Logical and Physical diagram/relationships of OBIEE.
    My question is in regards to the validity of the following relationship to be used in a data warehouse based on what's currently in OBIEE. When I model this via Erwin, I'm wondering if I'm way off base in the relationships (modeling, not personal):
    Dimension 1 has a 0:M with Dimension 2
    Dimension 1 has a 0:M with Dimesion 3
    Dimension 2 has a 0:M with Dimension 3
    Both Dimension 2 and Dimension 3 have a 0:M with Fact 1
    Through the use of aliases and such, this does work in OBIEE. Will this work as a data model for a data warehouse environment?
    Thanks!

    I think you started with the wrong foot. I suggest you search in Google for "kimball methodology" and have a read at a few articles. Your DWH model should not be based on your transactional tables. You should ask your business users what "questions" they want to answer in the DWH. Then model your DWH base on that. You can not model a DWH without knowing what questions you need to answer. For instance if your business users want to know the sales per day and per branch you will a sales fact with a sales amount measure joining to two dimensions branch and time dimension. The number of facts will depend on the questions you need to answer, the type of data and the granularity of them.

  • SQL query against ConfigMgr DB causing 100% cpu usage on SQL server throughout day

    Hi, I am hoping someone here may have an idea of what I can do to resolve this as I am not much of a SQL guy. Here is what I know. Throughout the day, monday-friday, my ConfigMgr SQL server sits at 98-100% processor usage.
    Using the following query I have narrowed down the culprit of the high cpu usage throughout the day:
    SELECT p.spid, p.status, p.hostname, p.loginame, p.cpu, r.start_time, r.command,
    p.program_name, text
    FROM sys.dm_exec_requests AS r,
    master.dbo.sysprocesses AS p
    CROSS APPLY sys.dm_exec_sql_text(p.sql_handle)
    WHERE p.status NOT IN ('sleeping', 'background')
    AND r.session_id = p.spid
    Even though my knowledge of SQL is light, I believe the following output clearly defines the thread responsible for the high cpu usage. This "program_name" is present throughout the day and as long as its there, cpu usage remains at or near 100%:
    The text output of the above culprit is as follows (sorry this is long):
    -- Name : spDrsSummarizeSendHistory
    -- Definition : SqlObjs
    -- Scope : CAS_OR_PRIMARY_OR_SECONDARY
    -- Object : P
    -- Dependencies : <Detect>
    -- Description : Summarize DrsSendHistory information into DrsSendHistorySummary
    CREATE PROCEDURE spDrsSummarizeSendHistory
    AS
    BEGIN
    SET NOCOUNT ON;
    DECLARE @CurrentTime DateTime;
    DECLARE @SiteCode nvarchar(3);
    DECLARE @LastSummarizationTime DateTime;
    DECLARE @NextSummarizationTime DateTime;
    DECLARE @Interval INT; -- summarize interval in minutes
    DECLARE @ReplicationID INT
    DECLARE @iMaxID INT
    DECLARE @iCurrentID INT
    DECLARE @iBatchSize INT = 50
    DECLARE @ReplicationPattern NVARCHAR(255)
    DECLARE @TargetSite NVARCHAR(3);
    DECLARE @TimeTable TABLE (TargetSite NVARCHAR(3), StartTime DATETIME, EndTime DATETIME, PRIMARY KEY (TargetSite, StartTime, EndTime))
    DECLARE @TargetSites TABLE (SiteCode NVARCHAR(3) PRIMARY KEY)
    DECLARE @ChildTargetSites TABLE (TargetSite NVARCHAR(3), LastSummarizationTime DATETIME, [Interval] INT, PRIMARY KEY (TargetSite))
    DECLARE @ReplicationGroup TABLE (ID INT, ReplicationPattern NVARCHAR(255))
    IF OBJECT_ID(N'TempDB..#DrsSendHistorySummary') IS NOT NULL
    DROP TABLE #DrsSendHistorySummary
    CREATE TABLE #DrsSendHistorySummary (ID BIGINT IDENTITY(1, 1) NOT NULL, SourceSite NVARCHAR(3), TargetSite NVARCHAR(3), ReplicationGroupID INT, SyncDataSize BIGINT, CompressedSize BIGINT, UnCompressedSize BIGINT, MessageCount INT, ChangeCount INT, SummarizationTime DATETIME, PRIMARY KEY (ID))
    SET @CurrentTime = GETUTCDATE();
    SET @SiteCode = dbo.fnGetSiteCode();
    INSERT INTO @ReplicationGroup (ID, ReplicationPattern)
    SELECT RD.ID, RD.ReplicationPattern
    FROM ReplicationData RD
    WHILE EXISTS (SELECT * FROM @ReplicationGroup)
    BEGIN
    SELECT TOP (1) @ReplicationID = ID, @ReplicationPattern = ReplicationPattern FROM @ReplicationGroup
    TRUNCATE TABLE #DrsSendHistorySummary
    IF (((@ReplicationPattern = N'global' OR @ReplicationPattern=N'site') AND dbo.fnIsPrimary() = 1)
    OR (@ReplicationPattern = N'global_proxy' AND dbo.fnIsSecondary() = 1))
    BEGIN -- when current site is child
    SET @LastSummarizationTime = ISNULL(( SELECT MAX(SummarizationTime) FROM DrsSendHistorySummary WHERE SourceSite = @SiteCode AND ReplicationGroupID = @ReplicationID),
    (SELECT MIN(EndTime) FROM DrsSendHistory WHERE ReplicationGroupID = @ReplicationID) );
    SET @Interval = ISNULL((SELECT VALUE FROM RCMSQLCONTROLPROPERTY SCP, RCMSQLCONTROL SC
    WHERE SCP.ControlID = SC.ID AND SCP.Name = N'Send History Summarize Interval' AND SC.TypeID = 3 and SC.SiteNumber = dbo.fnGetSiteNumber()), 15); -- default 15 minutes
    DELETE @TargetSites
    INSERT INTO @TargetSites (SiteCode)
    SELECT DISTINCT SiteCode FROM DRS_MessageActivity_Send WHERE ReplicationID = @ReplicationID
    IF @LastSummarizationTime IS NOT NULL AND EXISTS (SELECT * FROM @TargetSites)
    BEGIN
    SET @NextSummarizationTime = DATEADD( minute, DATEDIFF(minute, 0, @LastSummarizationTime)/@Interval *@Interval + @Interval, 0);
    -- Summarized according to interval
    DELETE @TimeTable
    WHILE (@CurrentTime >= @NextSummarizationTime )
    BEGIN
    INSERT INTO @TimeTable (TargetSite, StartTime, EndTime)
    SELECT SiteCode, @LastSummarizationTime, @NextSummarizationTime FROM @TargetSites
    SET @LastSummarizationTime = @NextSummarizationTime;
    SET @NextSummarizationTime = DATEADD(mi, @Interval, @NextSummarizationTime );
    END
    INSERT INTO #DrsSendHistorySummary (SourceSite, TargetSite, ReplicationGroupID, SyncDataSize, CompressedSize, UnCompressedSize, MessageCount, ChangeCount, SummarizationTime)
    SELECT @SiteCode, T.TargetSite, @ReplicationID, SUM(ISNULL(D.SyncDataSize, 0)), SUM(ISNULL(D.CompressedSize, 0)), SUM(ISNULL(D.UnCompressedSize, 0)), SUM(ISNULL(D.MessageCount, 0)), SUM(ISNULL(ChangeCount, 0)), T.EndTime
    FROM DrsSendHistory D RIGHT JOIN @TimeTable T ON D.EndTime >= T.StartTime AND D.EndTime < T.EndTime AND ReplicationGroupID = @ReplicationID AND T.TargetSite = D.TargetSite
    GROUP BY T.TargetSite, T.StartTime, T.EndTime;
    END
    END
    ELSE IF ((@ReplicationPattern = N'global' AND dbo.fnIsCAS() = 1)
    OR (@ReplicationPattern = N'global_proxy' AND dbo.fnIsPrimary() = 1))
    BEGIN -- when current site is parent
    DELETE @ChildTargetSites
    INSERT INTO @ChildTargetSites(TargetSite, LastSummarizationTime, [Interval])
    SELECT DISTINCT(DSH.SiteCode),
    ISNULL(( SELECT MAX(SummarizationTime) FROM DrsSendHistorySummary WHERE SourceSite = @SiteCode AND ReplicationGroupID = @ReplicationID AND TargetSite=DSH.SiteCode),
    (SELECT MIN(EndTime) FROM DrsSendHistory WHERE ReplicationGroupID = @ReplicationID) ) AS LastSummarizeTime,
    ISNULL((SELECT VALUE FROM RCMSQLCONTROLPROPERTY SCP, RCMSQLCONTROL SC WHERE SCP.ControlID = SC.ID AND SCP.Name = N'Send History Summarize Interval' AND SC.TypeID = 3 and SC.SiteNumber = dbo.fnGetSiteNumberBySiteCode(DSH.SiteCode)), 15) AS Interval
    FROM DRS_MessageActivity_Send DSH WHERE DSH.ReplicationID = @ReplicationID
    GROUP BY DSH.SiteCode;
    DELETE @TimeTable
    WHILE EXISTS (SELECT * FROM @ChildTargetSites)
    BEGIN
    SELECT TOP (1) @TargetSite = TargetSite, @LastSummarizationTime = LastSummarizationTime, @Interval = Interval FROM @ChildTargetSites
    SET @NextSummarizationTime = DATEADD( minute, DATEDIFF(minute, 0, @LastSummarizationTime)/@Interval *@Interval + @Interval, 0);
    -- Summarized according to interval
    WHILE (@CurrentTime >= @NextSummarizationTime )
    BEGIN
    INSERT INTO @TimeTable (TargetSite, StartTime, EndTime)
    SELECT @TargetSite, @LastSummarizationTime, @NextSummarizationTime
    SET @LastSummarizationTime = @NextSummarizationTime;
    SET @NextSummarizationTime = DATEADD(mi, @Interval, @NextSummarizationTime );
    END
    DELETE @ChildTargetSites WHERE TargetSite = @TargetSite
    END;
    INSERT INTO #DrsSendHistorySummary (SourceSite, TargetSite, ReplicationGroupID, SyncDataSize, CompressedSize, UnCompressedSize, MessageCount, ChangeCount, SummarizationTime)
    SELECT @SiteCode, T.TargetSite, @ReplicationID, SUM(ISNULL(D.SyncDataSize, 0)), SUM(ISNULL(D.CompressedSize, 0)), SUM(ISNULL(D.UnCompressedSize, 0)), SUM(ISNULL(D.MessageCount, 0)), SUM(ISNULL(D.ChangeCount, 0)), @NextSummarizationTime
    FROM DrsSendHistory D RIGHT JOIN @TimeTable T ON D.EndTime >= T.StartTime AND D.EndTime < T.EndTime AND ReplicationGroupID = @ReplicationID AND T.TargetSite = D.TargetSite
    GROUP BY T.TargetSite, T.StartTime, T.EndTime;
    END;
    SELECT @iMaxID = MAX(ID), @iCurrentID = 0 FROM #DrsSendHistorySummary
    -- BATCH INSERT TO REAL TABLE
    WHILE (@iCurrentID < @iMaxID)
    BEGIN
    INSERT INTO DrsSendHistorySummary (SourceSite, TargetSite, ReplicationGroupID, SyncDataSize, MessageCount, ChangeCount, SummarizationTime)
    SELECT SourceSite, TargetSite, ReplicationGroupID, SyncDataSize, MessageCount, ChangeCount, SummarizationTime
    FROM #DrsSendHistorySummary WHERE ID > @iCurrentID AND ID <= (@iCurrentID + @iBatchSize)
    SET @iCurrentID = @iCurrentID + @iBatchSize
    END
    TRUNCATE TABLE #DrsSendHistorySummary
    DELETE @ReplicationGroup WHERE ID = @ReplicationID
    END
    END
    If anyone has any experience with this issue or anything similar and might be able to point me in the right direction, any responses would be greatly appreciated. Thanks for reading!

    Normally, this summary job every few mins which only summarize last few mins sending history. If the job was not running for long time, the first time, this sproc will summarize a lot more data than normal. So it could fail which will make things worse and
    worse over time.
    If sending summary data is not a big concern here, you can manually insert a dummy row with most recent time as Summarizationtime, so that, when summary job kicks in next time, it will only summary short interval data.
    DrsSendHistory is that the table records every sending on every group. This table is one of the key of replication logic. For your environment, on primary site, it could have up to 24(hrs) * 60 (mins) / 2 (sync interval) * 36(secondary sites) records per
    day for Secondary_Site_Replication_Configuration group and 24 * 60 / 5 * 22 records for Secondary Site Data.
    Umair Khan | http://blogs.technet.com/umairkhan
    Hi Umair,
    Thank you for the reply. My plan was to go ahead with your suggestions but what I tried first was to get my VM guy to give the SQL server access to more CPU resources. We had already configured it with what would have seemed to be plenty, as per Microsoft's
    sizing requirements, but I figured it couldn't hurt to rule out - he gave the SQL server access to a huge portion of the host processing power and since then CPU usage on the server has NOT been an issue.
    It would appear that the large amounts of secondary sites we have just simply put a lot of stress on the SQL server with out of the box replication settings. Since the entire VM host is for System Center only, and our other System Center servers are using
    very little resources, this solution has ended up being valid.
    Thanks again for everyone's help with this.

  • Previous day date to pick up

    i want to pick up the previous latest date from a column. that means
    if i have a column name batch_id and the dates avaiable are
    batch_id Previous date
    27-06-07 26-06-07
    26-06-07 25-06-07
    25-06-07 23-06-07 -----saturday date out here
    Its a sunday therefore no business for this day and therefore no entry for this day.
    23-06-07 22-06-07
    please let me know how to achive this through SQL
    Thanks in advance

    Is this?
    select batch_id
      ,case when to_cahr(batch_id,'fmday','nls_date_language=american') = 'monday'
        then batch_id-3
        else batch_id-1
       end  previous_date
    from your_table
    ;But, how do you want to treate holidays?

  • ST03 - Previous day data???

    Hi Guru's,
    I have a query on ST03. My Question is when I log onto a server and try to get the ST03 data for the previous day, I do not get the data until 3AM server time. ie if I want the data for 3/12/08, the data does not reflect on the system till 3AM 3/13/08. Why is it I do not get the data of the previous day at 12.10AM on 3/13/08.
    Useful answers will be rewarded.
    Cheers
    Shankam

    Hi Praveen,
    1) SAP standard job SAP_COLLECTOR_FOR_PERFORMANCE must be schedule hourly in each SAP system. The job must always be scheduled in client 000 with user DDIC or with a user with the same authorisation.
    2) If you want to schedule the SAP_COLLECTOR_FOR_PERFORMANCE job daily. Can you check when SAP_COLLECTOR_FOR_PERFORMANCE job has been scheduled. If you can change the schedule time of SAP_COLLECTOR_FOR_PERFORMANCE job, i think it should resolve your problem.
    Kindly refer below sap notes
    *Note 12103 - Contents of the TCOLL table*
    *Note 16083 - Standard jobs, reorganization jobs*
    Cheers
    Kanthi Kiran

  • Error when insert data in Sql Server table(DateTime data type)

    Hello all,
    I have created a database link in oracle 11g to SQL Server 2008 using Sqlserver gateway for oracle,Oracle run on Linux and SQL Server run on Windows platform.
    I have queried a table and it fetches rows from the target table.
    I am using this syntax for insert a row in Sql Server table.
    Insert into Prod@sqlserver (NUMITEMCODE, NUMPREOPENSTOCK, NUMQNTY, NUMNEWOPENSTOCK, DATPRODDATE , TXTCOMPANYCODE, "bolstatus", NUMRESQNTY )
    Values (1118 , 1390.0 , 100.0 ,1490 , '2012-06-23 12:37:58.000','SFP' ,0 , 0 );
    but it give me error on DATPRODDATE,The data type of DATPRODDATE column in Sql Server is DATETIME.
    My Question is how can i pass the date values in INSERT statement for Sql Server DateTime data type.
    Regards

    Just as with Oracle, you have to specify the date using the to_date() function or use the native date format for the target database (if you can figure out what that is). This is good practice anyway and a good habit to get into.

  • What should I use BCS or directly connect to sql server to get data.

    Hi All,
    I have a requierment where the data is in the sql server.
    We  are using sharepoint webpart to show the data from the sql.
    Should i get the data from the sql server using connection string.
    Is there any better way to get data from Sql server table and show that in the custom asp.net form.
    Regards
    Vinod

    As I see the questions is in SharePoint 2013 forum.
    Assuming you have SharePoint 2013/2010, you can create Create/Read/Update/Delete operations on directly sql table using BCS service of SharePoint. That will save you default development of web part and handle all information properly.
    If you don't want to use BCS and sql (not sharepoint sql) information required, you can create custom web part/app part.
    Thanks, Ashish | Please mark a post helpful/answer if it is helpful or answer your query.

Maybe you are looking for