dbTalk Databases Forums  

Date manipulation

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Date manipulation in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Billy
 
Posts: n/a

Default Date manipulation - 03-20-2006 , 08:48 AM






I need to write a DTS package which is date oriented and I'm having problems
getting something coherent. I'm not a big guy in SQL Server, so please excuse
my ignorance.

I need to get some sales information based on the previous day...however, if
the previous day was Monday, then I need to get the sales data for the
Friday. The where clause looks like this (and it's not
working....unsurprisingly).
/*****************************************
where
case upper(datename(dd,getdate())) = 'MONDAY'
then
ididat = getdate(dateadd(day,-3,getdate()))
--and ididat < 20060320
else
ididat = getdate(dateadd(day,-1,getdate()))
--and ididat < 20060320
end
/*****************************************

Any ideas?

Thx for your help

Reply With Quote
  #2  
Old   
Andrew
 
Posts: n/a

Default Re: Date manipulation - 03-20-2006 , 02:42 PM






Hi Billy,

The first thing you might try is using 'dw' (no quotes) as the first
parameter to datename( ). This should return the string you're looking for.
Books Online (BOL) has a listing of valid params.

Andrew


"Billy" <Billy (AT) discussions (DOT) microsoft.com> wrote

Quote:
I need to write a DTS package which is date oriented and I'm having
problems
getting something coherent. I'm not a big guy in SQL Server, so please
excuse
my ignorance.

I need to get some sales information based on the previous day...however,
if
the previous day was Monday, then I need to get the sales data for the
Friday. The where clause looks like this (and it's not
working....unsurprisingly).
/*****************************************
where
case upper(datename(dd,getdate())) = 'MONDAY'
then
ididat = getdate(dateadd(day,-3,getdate()))
--and ididat < 20060320
else
ididat = getdate(dateadd(day,-1,getdate()))
--and ididat < 20060320
end
/*****************************************

Any ideas?

Thx for your help



Reply With Quote
  #3  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Date manipulation - 03-20-2006 , 03:07 PM



Hello Billy,

Not tested

It should look something similar to

....
WHERE
CONVERT(CHAR(8),<date column>,112) =
CASE
WHEN DATENAME(dw,DATEADD(day,-1,Getdate())) = 'MONDAY' THEN DATEADD(day,-3,CONVERT(CHAR(8),DATEADD(day,-1,Getdate()),112))
ELSE CONVERT(CHAR(8),DATEADD(day,-1,Getdate()),112)
END



Allan Mitchell
www.SQLDTS.com
www.SQLIS.com
www.Konesans.com

Quote:
I need to write a DTS package which is date oriented and I'm having
problems getting something coherent. I'm not a big guy in SQL Server,
so please excuse my ignorance.

I need to get some sales information based on the previous
day...however, if
the previous day was Monday, then I need to get the sales data for the
Friday. The where clause looks like this (and it's not
working....unsurprisingly).
/*****************************************
where
case upper(datename(dd,getdate())) = 'MONDAY'
then
ididat = getdate(dateadd(day,-3,getdate()))
--and ididat < 20060320
else
ididat = getdate(dateadd(day,-1,getdate()))
--and ididat < 20060320
end
/*****************************************
Any ideas?

Thx for your help





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.