[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Create Date/Time field from 2 other fields

Sawlmgsj

3/15/2007 12:56:00 PM

I have a table with 2 fields - a Date/Time containing an appointment date and
a VarChar containing an appointment time in a format such as 11:30 (I have
inherited this arrangement from an existing structure. I could change the
format of the time if necessary.)

I need to create an UPDATE trigger that populates another true Date/Time
field with both parts (of the appointment) whenever the separate date or time
fields are changed.

I need a true Date/Time field in order to populate a diary system.

Can you help?

Thanks,
Steve.


2 Answers

Russell Fields

3/15/2007 1:31:00 PM

0

Steve,

Use CONVERT styles and string concatenation.

declare @date datetime
declare @hour varchar(10)

select @date = '1/1/2007'
select @hour = '11:30'

select CONVERT(DATETIME, CONVERT(VARCHAR(10), @date, 101) + ' ' + @hour)

RLF

"Sawlmgsj" <Sawlmgsj@discussions.microsoft.com> wrote in message
news:EF3E162E-E45B-4A5A-B983-C5FBD6417849@microsoft.com...
>I have a table with 2 fields - a Date/Time containing an appointment date
>and
> a VarChar containing an appointment time in a format such as 11:30 (I have
> inherited this arrangement from an existing structure. I could change the
> format of the time if necessary.)
>
> I need to create an UPDATE trigger that populates another true Date/Time
> field with both parts (of the appointment) whenever the separate date or
> time
> fields are changed.
>
> I need a true Date/Time field in order to populate a diary system.
>
> Can you help?
>
> Thanks,
> Steve.
>
>


Sawlmgsj

3/16/2007 8:35:00 AM

0

Russell - many thanks for the help - Steve.



"Russell Fields" wrote:

> Steve,
>
> Use CONVERT styles and string concatenation.
>
> declare @date datetime
> declare @hour varchar(10)
>
> select @date = '1/1/2007'
> select @hour = '11:30'
>
> select CONVERT(DATETIME, CONVERT(VARCHAR(10), @date, 101) + ' ' + @hour)
>
> RLF
>
> "Sawlmgsj" <Sawlmgsj@discussions.microsoft.com> wrote in message
> news:EF3E162E-E45B-4A5A-B983-C5FBD6417849@microsoft.com...
> >I have a table with 2 fields - a Date/Time containing an appointment date
> >and
> > a VarChar containing an appointment time in a format such as 11:30 (I have
> > inherited this arrangement from an existing structure. I could change the
> > format of the time if necessary.)
> >
> > I need to create an UPDATE trigger that populates another true Date/Time
> > field with both parts (of the appointment) whenever the separate date or
> > time
> > fields are changed.
> >
> > I need a true Date/Time field in order to populate a diary system.
> >
> > Can you help?
> >
> > Thanks,
> > Steve.
> >
> >
>
>
>