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


Need DateTime format and count of records


Need DateTime format and count of records

Author
Message
srisagar_p
srisagar_p
SSC Veteran
SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)

Group: General Forum Members
Points: 219 Visits: 108
Hi all,

I need small query which determines DateTime and count of records of a table.

Example:
Table1: this table has records like this:
13/01/2010(DD/MM/YYYY)
01/13/2010(MM/DD/YYYY)
14/04/2001(DD/MM/YYYY)
11/03/2002(MM/DD/YYYY)
2010/01/01(YYYY/MM/DD)
the result should be like this:

datetime count
----------------------
DD/MM/YYYY 2
MM/DD/YYYY 2
YYYY/MM/DD 1


Can any one help on this.

Thank you all
Waiting for your good response..
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73242 Visits: 20317
CREATE TABLE #Sample (MyStuff VARCHAR(22))
INSERT INTO #Sample (MyStuff)
SELECT '13/01/2010(DD/MM/YYYY)' UNION ALL
SELECT '01/13/2010(MM/DD/YYYY)' UNION ALL
SELECT '14/04/2001(DD/MM/YYYY)' UNION ALL
SELECT '11/03/2002(MM/DD/YYYY)' UNION ALL
SELECT '2010/01/01(YYYY/MM/DD)'

SELECT RIGHT(MyStuff, 12), COUNT(*)
FROM #Sample
GROUP BY RIGHT(MyStuff, 12)



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

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
Exploring Recursive CTEs by Example Dwain Camps
parthi-1705
parthi-1705
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3604 Visits: 2196
srisagar_p (10/25/2010)
Hi all,

I need small query which determines DateTime and count of records of a table.

Example:
Table1: this table has records like this:
13/01/2010(DD/MM/YYYY)
01/13/2010(MM/DD/YYYY)
14/04/2001(DD/MM/YYYY)
11/03/2002(MM/DD/YYYY)
2010/01/01(YYYY/MM/DD)
the result should be like this:

datetime count
----------------------
DD/MM/YYYY 2
MM/DD/YYYY 2
YYYY/MM/DD 1


Can any one help on this.

Thank you all
Waiting for your good response..


Hi
My understanding is
This are the formates you have given, these things you will not store in the database
MM/DD/YYYY or YYYY/MM/DD

CREATE TABLE #Sample1 (MyStuff VARCHAR(22))
INSERT INTO #Sample1 (MyStuff)
SELECT '13/01/2010' UNION ALL
SELECT '01/13/2010' UNION ALL
SELECT '14/04/2001' UNION ALL
SELECT '11/03/2002' UNION ALL
SELECT '2010/01/01'

Select MyStuff,case when RIGHT (left(MyStuff, 3),1) ='/' then 2 else 1 end [count] from #Sample1

DROP TABLE #Sample1

Thanks
Parthi

Thanks
Parthi
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