Solved

Insert time into date/time field sql server

Posted on 2007-03-28
4
878 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

863 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

24 Experts available now in Live!

Get 1:1 Help Now