Solved

Insert time into date/time field sql server

Posted on 2007-03-28
4
884 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 143

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 143

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

630 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