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
Solved

Insert time into date/time field sql server

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

809 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