On a paramater of datepart (like the first one in DateAdd),
can I in any chance pass a parameter?
(and not use the constants week, month etc.)
SELECT DateAdd(@.my_dt , 1 , CONVERT (DATETIME, '01/01/01')) As 'Date'
I think you would need dynamic SQL, e.g.
EXEC('SELECT DateAdd(' + @.my_dt + ', 1, ...') AS [Date];
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
<retima@.gmail.com> wrote in message
news:1174495911.706163.321400@.e65g2000hsc.googlegr oups.com...
> On a paramater of datepart (like the first one in DateAdd),
> can I in any chance pass a parameter?
> (and not use the constants week, month etc.)
> SELECT DateAdd(@.my_dt , 1 , CONVERT (DATETIME, '01/01/01')) As 'Date'
>
|||You could use brute force.
DECLARE @.d datetime
SET @.d = GETDATE()
DECLARE @.x int
SET @.x = 7
SELECT CASE @.x
WHEN 1 THEN DATEPART(year, @.d)
WHEN 2 THEN DATEPART(quarter, @.d)
WHEN 3 THEN DATEPART(month, @.d)
WHEN 4 THEN DATEPART(dayofyear, @.d)
WHEN 5 THEN DATEPART(day, @.d)
WHEN 6 THEN DATEPART(week, @.d)
WHEN 7 THEN DATEPART(weekday, @.d)
WHEN 8 THEN DATEPART(hour, @.d)
WHEN 9 THEN DATEPART(minute, @.d)
WHEN 10 THEN DATEPART(second, @.d)
WHEN 11 THEN DATEPART(millisecond, @.d)
END as SomePart
Roy Harvey
Beacon Falls, CT
On 21 Mar 2007 09:51:51 -0700, retima@.gmail.com wrote:
>On a paramater of datepart (like the first one in DateAdd),
>can I in any chance pass a parameter?
>(and not use the constants week, month etc.)
>SELECT DateAdd(@.my_dt , 1 , CONVERT (DATETIME, '01/01/01')) As 'Date'
|||On Mar 21, 8:14 pm, Roy Harvey <roy_har...@.snet.net> wrote:
> You could use brute force.
> DECLARE @.d datetime
> SET @.d = GETDATE()
> DECLARE @.x int
> SET @.x = 7
> SELECT CASE @.x
> WHEN 1 THEN DATEPART(year, @.d)
> WHEN 2 THEN DATEPART(quarter, @.d)
> WHEN 3 THEN DATEPART(month, @.d)
> WHEN 4 THEN DATEPART(dayofyear, @.d)
> WHEN 5 THEN DATEPART(day, @.d)
> WHEN 6 THEN DATEPART(week, @.d)
> WHEN 7 THEN DATEPART(weekday, @.d)
> WHEN 8 THEN DATEPART(hour, @.d)
> WHEN 9 THEN DATEPART(minute, @.d)
> WHEN 10 THEN DATEPART(second, @.d)
> WHEN 11 THEN DATEPART(millisecond, @.d)
> END as SomePart
> Roy Harvey
> Beacon Falls, CT
> On 21 Mar 2007 09:51:51 -0700, ret...@.gmail.com wrote:
>
>
> - Show quoted text -
thanx guys, that helped!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment