Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 date

Author  Topic 

kemi2299
Starting Member

41 Posts

Posted - 2008-04-11 : 09:23:36
hi
could you pls help in how i can convert this statement into tsql
thanks

UPDATE stemp34
SET apdate_flag=1
WHERE app_date>= date_trunc('month', 'today') - '2 months'
AND app_date < date_trunc('month','today') - '1 month'
AND dna_ind IN (5,6);

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-11 : 09:30:41
[code]UPDATE stemp34
SET apdate_flag=1
WHERE app_date>= dateadd(month, -2, dateadd(day, datediff(day, 0, getdate()), 0))
AND app_date < dateadd(month, -1, dateadd(day, datediff(day, 0, getdate()), 0)) AND dna_ind IN (5,6)[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-04-11 : 09:33:29
doesn't date_trunc on a month do the equivalent of
dateadd(month, datediff(month, 0, getdate()), 0))
rather than day?



Em
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-11 : 09:45:26
quote:
Originally posted by elancaster

doesn't date_trunc on a month do the equivalent of
dateadd(month, datediff(month, 0, getdate()), 0))
rather than day?



Em



It will return the first day of the month. I am not sure if OP wants that.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-11 : 09:48:16
quote:
Originally posted by elancaster

doesn't date_trunc on a month do the equivalent of
dateadd(month, datediff(month, 0, getdate()), 0))
rather than day?



Em


Yes it is

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -