SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


date column behaving strangely


date column behaving strangely

Author
Message
sqldriver
sqldriver
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2302 Visits: 2536
hi,

i have a column that's treating dates in an odd way.

select filldate, datediff(dd, filldate, getdate()) as Diff
from j2551963
group by filldate
having datediff(dd, filldate, getdate()) < 13
order by filldate



filldate Diff
03/01/2013 12
03/02/2013 11
03/03/2013 10
03/04/2013 9
03/05/2013 8
03/06/2013 7
03/07/2013 6
03/08/2013 5


select filldate, count(*) as Records
from j2551963
where filldate like '03/%'
group by filldate
order by filldate



filldate Records
03/01/2013 2728
03/02/2013 1228
03/03/2013 908
03/04/2013 2525
03/05/2013 2497
03/06/2013 2153
03/07/2013 2086
03/08/2013 1726

select convert(varchar, filldate, 101)as FillDate, count(*) as Records
from j2551963
group by filldate
having datediff(dd, convert(varchar, filldate, 101), getdate()) < 13
order by filldate



FillDate Records
03/01/2013 2728
03/02/2013 1228
03/03/2013 908
03/04/2013 2525
03/05/2013 2497
03/06/2013 2153
03/07/2013 2086
03/08/2013 1726

here is column information:

id_Field Field_vartype Field_Varsize SourceName
FillDate nvarchar 64 FillDate

data was imported from excel files. i guess my question is: how come just a few columns are recognized by the datediff without a convert statement? is it an excel issue, or an import issue? i know that's a bit open ended without posting more information, but i'm curious if there's an answer before getting deeper into it.

thanks
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98532 Visits: 38996
I can't figure out what your problem is here.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Sean Lange
Sean Lange
SSC Guru
SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)SSC Guru (65K reputation)

Group: General Forum Members
Points: 65112 Visits: 17979
Seems to me that the only real issue here is that you have a varchar(64) column that should be a datetime column.

As you said yourself, there is not much information here to go on. Perhaps if you post some details we can help.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
sqldriver
sqldriver
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2302 Visits: 2536
heh. no. i had a monumental brainfart.

i was looking at the 'diff' column like it was a count, not like it was showing the difference between the two dates.

sorry about that, and thanks for looking. as soon as this three week old lets me get some sleep, i'll have better questions.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search