Click to See Complete Forum and Search --> : Inserting date and time on Update or Insert


nate47
01-31-2007, 11:16 AM
Hi,

I'm somewhat of a novice to SQL, so apologies in advance for my ignorance.
I'm looking to to find if anyone knows the best way to add Date and Time to their own columns upon Insert or Update into the table.

Currently I have the columns ID, Email and SWAN, but have added Date and Time, in lieu of adding this functionality.

I'm using MS SQL.

Are triggers the best way to go about this, or can anyone recommend another way?
If so, does anyone have an example syntax that I could use/modify?

Cheers,

Nate

russell
01-31-2007, 11:46 AM
i'd create two columns, both smalldatetime and insert directly, stripping off the date or timestamp accordingly. what is doing the inserting? an app, or a T-SQL script?

here's how to get the date portion

select convert(smalldatetime, left(getdate(), 11))

but if an application is doing the inserting, may be best to use the application language's date and time methods.

nate47
01-31-2007, 11:51 AM
It's an ASP script that is insterting the data.

I'll write a script to insert that too then :)

Cheers