Re: Update 'Date': Set Day(Date) to a Certain Number



On Wed, 4 Jan 2006 05:31:07 -0800, PML wrote:

>Hi,
>
>I am trying to use an update command to set the day of a date to a certain
>number. For example, if the date is 1/4/06, I might want to set day(date) to
>'7'. So it turns into 1/7/06. I wasn't sure if there was a way to do this
>and I keep getting errors when I try it.

Hi PML,

And here's a third way: convert existing date to YYYYMM, add string
representation of wanted day to arrive at YYYYMMDD, convert back to
date:

SELECT CAST(CONVERT(char(6), @datetime, 112)
+ RIGHT('0' + CAST(@newDay AS varchar(2)), 2) AS datetime)

Best, Hugo

--
Angband spoilers: http://ourworld.compuserve.com/homepages/hugo_kornelis/Angband/Spoiler/index.htm
Angband UI Patch: http://ourworld.compuserve.com/homepages/hugo_kornelis/Angband/UIpatch/index.htm
--
.