Solved

DATETIME SQL

Posted on 2014-09-03
8
455 Views
Last Modified: 2014-09-03
Good Day

Need help with DATETIME conversion in T-SQL.

Aantal as Qty,
Class as sClass,
mg as MassGrp,
Mass,
Product,
iso as Salesbrand

from bcGraderings where 

gdate >= CONVERT(DATETIME, @StartDate, 102)
 and 
 gdate <= CONVERT(DATETIME, @EndDate, 102)

Open in new window


Here is an example of the data in the GDATE field.
2014-03-14 13:08:47.000

When running this query on today's date, its not returning anything. I think its converting the date to 2014-03-14 and dropping the  time.
0
Comment
Question by:Yeaktom
[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
  • 4
  • 3
8 Comments
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40301005
HI,

I think the PArameter @StartDate is declared as Date

that is why it is not returning time and just comparing dates
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40301015
What are the values for @StartDate and @EndDate?
0
 
LVL 2

Author Comment

by:Yeaktom
ID: 40301056
@Start Parameters
Available Values is set to none
Default Values set to No Default
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40301069
What value is passed to that parameter?
0
 
LVL 2

Author Comment

by:Yeaktom
ID: 40301073
Here is a screenshot
Parameter Selection
0
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40301096
Ok. You aren't providing the time only the date.
So, if you have same StartDate and EndDate (like for today) your query will be:
gdate >= '2014-09-03 00:00:00'  and gdate <= '2014-09-03 00:00:00'

Open in new window

Which means that only if you have a record with exactly '2014-09-03 00:00:00' will be returned.
Or you give tomorrows date as EndDate or you need to change your code to add one day to EndDate:
gdate >= CONVERT(DATETIME, @StartDate, 102)
 and 
 gdate <= CONVERT(DATETIME, @EndDate, 102)+1

Open in new window

0
 
LVL 2

Author Closing Comment

by:Yeaktom
ID: 40301124
Thanks Vitor!
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 40301159
You are welcome. Glad I could help.

Cheers
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

615 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