|
|
Subject:
SQL Server Query
Category: Computers > Programming Asked by: chrisasking-ga List Price: $6.00 |
Posted:
25 Sep 2005 06:53 PDT
Expires: 25 Oct 2005 06:53 PDT Question ID: 572342 |
|
There is no answer at this time. |
|
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 08:27 PDT |
Hi How abt the below qry SELECT date1, count(date1) as rows from table1 group by date1 thanks bala |
Subject:
Re: SQL Server Query
From: ukadamg-ga on 25 Sep 2005 09:22 PDT |
SELECT DATEPART (m, YourDateField) As Month, DATEPART (d, YourDateField) as Day, DATEPART (yy, YourDateField) as Year, Count (YourDateField) as Count, ' rows' from YourTable Group By DATEPART (m, YourDateField), DATEPART (d, YourDateField), DATEPART (yy, YourDateField) putting in the title of your date column in place of YourDateField and your table name in place of YourTable. That should work - shame I can't post it as an answer... bala has the right idea but didn't carry out the grouping to get rid of times... No need to Cast or Convert, which will only confuse... AG |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 10:04 PDT |
The output displays the date and their counts, so I thought not necessary to check the time. Thanks Bala |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 10:46 PDT |
sorry, mine wont work. thanks bala |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 11:53 PDT |
Hi Check out this query. SELECT CONVERT(char(12), DATEFIELD, 1),count(CONVERT(char(12), DATEFIELD, 1)),' rows' as result from TABLENAME group by CONVERT(char(12), DATEFIELD, 1) thanks bala |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 11:58 PDT |
This query will display by order. SELECT CONVERT(char(12), DATEFIELD, 1) as date,count(CONVERT(char(12), DATEFIELD, 1)) as count ,' rows' as result from TABLENAME group by CONVERT(char(12), DATEFIELD, 1) order by CONVERT(char(12), DATEFIELD, 1) desc DATEFIELD - your date field name TABLENAME - your table name Thanks Bala |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 25 Sep 2005 18:38 PDT |
Hi chrisasking, This query will give you the output. The problem is it will display one more column like order1. Let me know what do you think. SELECT CAST(Substring(CONVERT(char(12), curdate, 1) ,7,2) as int) as order1, CONVERT(char(12), curdate, 1) as date,count(CONVERT(char(12), curdate, 1)) as count ,' rows' as result from table1 group by CONVERT(char(12), curdate, 1),CAST(Substring(CONVERT(char(12), curdate, 1) ,7,2) as int) order by CAST(Substring(CONVERT(char(12), curdate, 1) ,7,2) as int) curdate - datefield table1 - table name Thanks Bala |
Subject:
Re: SQL Server Query
From: awilinsk-ga on 27 Sep 2005 08:26 PDT |
SELECT CONVERT(VARCHAR,date_field,1) as date_field FROM table_name GROUP BY CONVERT(VARCHAR,date_field,1); You can also change the format of the date that comes out by changing the third parameter. Here are the formats http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp |
Subject:
Re: SQL Server Query
From: pmmbala1976-ga on 27 Sep 2005 11:14 PDT |
Hi awilinsk, you query very simple. great! bala |
Subject:
Re: SQL Server Query
From: gmalpani-ga on 06 Oct 2005 02:43 PDT |
hi, convert your date column to varchar(10) and with style 103 or 3 and then use group by to find count select convert(varchar(10),YourDate,103), count(*), ' rows' from YourTable group by convert(varchar(10),YourDate,103) i think it will give u the result |
Subject:
Re: SQL Server Query
From: denbagusid-ga on 17 Oct 2005 06:29 PDT |
Hi, try my query: select convert(varchar(10), <your date time>,103), convert(varchar,count(*)) + ' rows' from <your table> group by convert(varchar(10), <your date time>,103) While: <your date time> is your field/column represent the datetime value <your table> is your table name. For example: select convert(varchar(10), myDate,103), convert(varchar,count(*)) + ' rows' from myTable group by convert(varchar(10), myDate,103) Cheer.. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |