November 30, 2009 at 11:22 pm
Hi,
I generate a report based on data sent by customer from Mon-Fri. Like if a customer sends data on Mon - his report will be generated on a Wednesday (some rules applied) and same for other weekdays.
Now I require to add extra functionality whereby if cust sends data on Saturday or Sunday , it also gets reported (which was not the case earlier).
Condition is:
"If cust sends data on Sat or Sun - it should be merged with Mon data and reported as if the data were send on Mon".
Now it is easy for me to just manually put Sat and Sun data into Mon data and do the reporting. However i would like to avoid doing it manually.
So if someone can help in out in designing a SP to search for any files on the last Saturday and Sunday & change the internal dates to make it look like it was loaded Monday (in every data file is included the date and time at which customer sent that particular file).
Tables used:
Data_control - stores the filename,fileadded(date),filedate,unique cust no.
Data_full - stores the details contained in the data sent by the customer.
Any help would be appreciated.
Umang
December 1, 2009 at 6:05 am
hi,
compare saturday and sunday with datename function (datename(w,datefield)) and build your logic.
hope this will help u.
thanks and regards
Raghavendra N S
December 1, 2009 at 11:46 am
Thanks Raghav.
Umang.
December 1, 2009 at 12:10 pm
I'n not sure how complicated your code is but if it's not too long, you could post it and we might have an even better suggestion.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 5, 2009 at 11:38 am
Guys,
Ive written a SP to handle Sat/Sun data. I ran the Exe to implement it, but it did not work for some reason. Can you help me out.
CREATE PROCEDURE usp_Load_Full
@file NVARCHAR(100),
@name NVARCHAR(30),
@folder CHAR(8),
AS
DECLARE @i INT, @filedate CHAR(8)
IF (DATENAME(dw,@folder)= 'Saturday')
BEGIN
SELECT id
FROM dbo.Customer C
JOIN dbo.DataControl PC ON C.Number=PC.Number
WHERE C.SatData=1
SET @i = @@ROWCOUNT
WHILE i >0
BEGIN
SET @filedate = DATEADD(dd,2,@folder)
INSERT INTO Data_Full
SELECT *, @name, @filedate, 0, 0
FROM Data_Load
WHERE Version = '1'
SET @i = @i -1
END
INSERT INTO Data_Full
SELECT *, @name, @folder, 0, 0
FROM Data_Load
WHERE Version = '1'
END
ELSE IF (DATENAME(dw,@folder)= 'Sunday')
BEGIN
SET @filedate = DATEADD(dd,1,@folder)
INSERT INTO Data_Full
SELECT *, @name, @filedate, 0, 0
FROM Data_Load
WHERE Version = '1'
END
The code should simply check for Sat data load, check a flag - if the flag is one then add 2 days to it to make it look it is Mon file..otherwise load as Sat file.
The sunday file does not check for any flag and simply should behave as if it is mond file.
Assume the 3 parameters passed to SP be available.
December 5, 2009 at 1:51 pm
something like this might get you started.
for any given week, this returns the starting date of monday(@12am, the start of friday, and the last possible datetime of friday.
from there, you could use dateadd to add minus two days to get the Saturday(teo days before) of "this weeks" monday,
SET DATEFIRST 1
SELECT
DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) Monday,
DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)+4 Friday,
DATEADD(ms,-3,DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) + 5 ) EODFriday
Lowell
December 7, 2009 at 11:27 pm
All,
I am alomost done with my bit to include weekend days, but failing in the last hurdle.
When i am using "SET" to modify the Sat date it is not alloowing the modified date to be stored in "yyyymmdd" format. It is storing in "Aug 31 2009" type format.
I want the modified date to look in "yyyymmdd" (the format of filedate is "yyyymmdd"). Below is the line in contention.
SET @filedate= DATEADD(dd,2,@filedate)
A quick response would be appreciated.
Thanks.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply