April 18, 2013 at 9:43 am
Seems simple enuf?
So I have a datetime field in a db which happens to be 04/10/2013
I do a
select * from orders
where
create_date like '%/10/%'
returns nothing.
So clear not that simple.
I have a URL with either a date &date=11/11/2011 or d=a&m=2&y=2012
I need to do w where (day in date_created=url.d) or some such.
Better still where date_created=url.date
Thanks for your patience with something that has to be SO simple ... did google it and looked up a couple of reference books!
April 18, 2013 at 9:50 am
britinusa (4/18/2013)
Seems simple enuf?So I have a datetime field in a db which happens to be 04/10/2013
I do a
select * from orders
where
create_date like '%/10/%'
returns nothing.
So clear not that simple.
I have a URL with either a date &date=11/11/2011 or d=a&m=2&y=2012
I need to do w where (day in date_created=url.d) or some such.
Better still where date_created=url.date
Thanks for your patience with something that has to be SO simple ... did google it and looked up a couple of reference books!
You can't query dates using like and expect it to work correctly. Dates are NOT strings. In your example you were looking for dates where the day is the 10th of the month. You would do that like this.
select * from orders
where
datepart(day, create_date) = 10
Does that 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 http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2013 at 10:21 am
Does that help?
Yes! Thanks!
April 18, 2013 at 10:27 am
britinusa (4/18/2013)
Does that help?Yes! Thanks!
You are welcome. You might take a look at BOL for DATEPART. There a number of things you can check for.
_______________________________________________________________
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 http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2013 at 10:56 am
BOL?
April 18, 2013 at 10:59 am
britinusa (4/18/2013)
BOL?
BOL = Books Online.
http://msdn.microsoft.com/en-us/library/ms130214.aspx
This should be in your arsenal of things you look at daily. The topic of SQL server is just entirely too large and complex to remember without a good reference.
_______________________________________________________________
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 http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 18, 2013 at 11:07 am
Thanks!
You made this "unintentional db admin / coder's" day!
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply