September 19, 2008 at 4:42 am
Hello
I have been trying to group a query by date, but anytime i try the default database date appears, can anyone help?
September 19, 2008 at 5:15 am
Check you data. Might be having default date.
Omit the same if you do not want that default date in where condition.
September 19, 2008 at 5:15 am
Hello,
Sorry, but I don’t really understand what your question is. Can you post your query?
Regards,
John Marsh
www.sql.lu
SQL Server Luxembourg User Group
September 19, 2008 at 5:30 am
Thanks all
I used the foloowing which worked for me:
SELECT SUBSTRING(CAST(OrderDate AS VARCHAR),1,11) AS OrderDate, .......
September 19, 2008 at 7:50 am
The proper way would be
group by dateadd(day,datediff(Day,0,date_col),0)
Failing to plan is Planning to fail
September 19, 2008 at 8:13 am
Madhivanan (9/19/2008)
The proper way would begroup by dateadd(day,datediff(Day,0,date_col),0)
For group by, it doesn't necessarily need to be cast back to a datetime:
datediff(Day,0,date_col)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 19, 2008 at 12:02 pm
sorry guys but my own syntax worked perfect for me, tried yours but got incorrect results....
September 19, 2008 at 3:18 pm
Not at all b_boy, it's a learning experience for us all. How about posting up some sample data and results? Everybody would appreciate this.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 19, 2008 at 4:56 pm
b_boy (9/19/2008)
sorry guys but my own syntax worked perfect for me, tried yours but got incorrect results....
If you used a conversion to group by date, then you probably did it the slow way... the ones that use DATEADD and/or DATEDIFF will be faster.
Instead of us guessing, would you please post your complete query and maybe some test data so we can help better? Please see the link in my signature below for what we really need to help you on this and other problems. Thanks. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply