Solved

DATETIME SQL

Posted on 2014-09-03
8
422 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
  • 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 47

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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 47

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 47

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 47

Expert Comment

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

Cheers
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

813 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

10 Experts available now in Live!

Get 1:1 Help Now