Solved

Insert time into date/time field sql server

Posted on 2007-03-28
4
877 Views
Last Modified: 2008-02-01
I have a date/time field in my sql server.  There are some records that only show the date but most show the date time and this is messing up some reports.  I want to put in a time into the records that only have the date.  Here is how I get the records with only a date: (DATEPART(hour, DateOfService) = 0)
AND (DATEPART(minute, DateOfService) = 0) AND (DATEPART(second, DateOfService) = 0)
Any idea on how I could do this.

Thanks
0
Comment
Question by:tbailey922
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18810799
> I want to put in a time into the records that only have the date
what time?

how does the report query?
0
 

Author Comment

by:tbailey922
ID: 18810863
The data is pushed into Access for reporting and when they run a report for a month it doesn't grab the the last day of the date entered if it doesn't have a time in it.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18810892
can you post the relevant query part (where clause) that pushes?
I assume it uses a wrong comparison...
0
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 125 total points
ID: 18812631
If you have the criteria to get the records that you want to update, then you only have to decide what time you are going to put in.

If you want to put 10:00 AM into the time, then I would use the criteria you have to use an UPDATE statement.

UPDATE tblname SET datetimefield = DATEADD(hour, 10, datetimefield)
WHERE (DATEPART(hour, DateOfService) = 0)
AND (DATEPART(minute, DateOfService) = 0) AND (DATEPART(second, DateOfService) = 0)

If you want to put a different time, then you would just do more DATEADDs, or construct it using CONVERT, etc.

Ben.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now