It would probably be helpful to see your code and it's not 100% clear what
you're trying to do. I'm guessing hour(now) is a .NET function? Does it
simply return the number of the current hour? That would be some sort of
INT, which would be a datatype mismatch with the datatypes you say you've
tried. Your note mentioned "insert the date and time", which wouldn't
simply be the current hour, anyway.
When I want to insert the date and time, I usually use SQL Server's
getdate() function to supply the value. A T-SQL example would be:
create table foo (col1 char(10),col2 datetime)
go
insert foo values ('abc',getdate())
go
select * from foo
go
[results]
(1 row(s) affected)
col1 col2
---------- ------------------------------------------------------
abc 2005-02-25 15:16:38.367
(1 row(s) affected)
Use the datetime datatype if you can. In my experience, using character or
numeric types for storing dates and times usually ends up in grief.
By the way, I usually set things up so that SQL Server is responsible for
supplying the time, rather than the application. That way, if the various
workstation's or web server's clocks are a little bit off, the time values
of rows inserted/updated will still be synchronized across your
applications.
<c_*****@earthlink.net> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to
insert the date and time into a SQL database by using hour(now). I am
having a hard time trying to figure out which datatype to use in SQL to
store this value. I have tried using datetime, char, nchar, text and
nothing seems to work. Anyone have any ideas? Thanks!
Regards, :)
Christopher Bowen