SQL PHP HTML ASP JavaScript articles and free scripts to download

Year Function of MSSQL DateTime field

Year we can read from MSSQL datetime field by using year function . Query is here

select Year(issue_dt) as Year, issue_dt from dt

The output is here
Yearissue_dt
2007 12/28/2007 7:54:56 PM
2010 10/31/2010 7:23:47 PM
2010 10/31/2010 7:30:14 PM
2010 10/31/2010 7:30:20 PM
2010 2/28/2010 7:54:56 PM
We have seen how month function is used along with group by function. Let us try to list out number of issues in the Year 2010 against months by using group by command and where clause. Here is the query

select COUNT(issue_dt) as no, Month(issue_dt) as isdt from dt WHERE Year(issue_dt)='2010' GROUP BY Month(issue_dt)

isdt no
2 1
10 3
The left column is the month and next column shows number of issues against that month for the year 2010.

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer