Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
ඕනම රටකට සෙට් වෙන CV එකක්
ErMurazor
Updated:
Saturday at 9:50 AM
Hambantota
7 Acres Beachfront Land For Sell DownSouth , PerPerch Price 420 000
1024 Digital
Updated:
Wednesday at 11:57 AM
Baseus PI LITE INDOOR CAMERA
ErMurazor
Updated:
Oct 12, 2026
Ad icon
Colombo
Hard Disk For Sale
mazza
Updated:
Oct 10, 2026
land for sale
justasking
Updated:
Oct 10, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
SQL danna aya enna....
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="sameemail" data-source="post: 22634505" data-attributes="member: 24079"><p><strong>Try This - Works with SQL 2008</strong></p><p></p><p><strong>Data Set </strong></p><p></p><p>ID StudentName DateOfBirth</p><p>1 saman 2015-01-02 </p><p>6 thilina 2015-08-10 </p><p>7 lahiru 2015-08-15 </p><p>5 nayana 2015-08-25 </p><p>4 kamal 2015-09-02 </p><p>2 nimal 2016-02-02 </p><p>9 kevin 2017-02-20 </p><p>8 kapila 2017-05-02 </p><p>3 amal 2017-05-02 </p><p>10 sirimal 2017-05-22 </p><p>----------------------------------------------</p><p><strong>Query</strong></p><p>--**Need to Enter the year (Any Year)</p><p></p><p>DECLARE @year INT</p><p>SET @year = 2015</p><p></p><p>SELECT A.MonthName ,</p><p> ISNULL(B.RecCount,0) AS NoOfBirthdays</p><p>FROM ( SELECT number AS MonthNumber ,</p><p> DATENAME(MONTH,</p><p> CAST(@year * 100 + number AS VARCHAR) + '01') AS MonthName</p><p> FROM master.dbo.spt_values</p><p> WHERE ( type = 'P' )</p><p> AND ( number BETWEEN 1 AND 12 )</p><p> ) AS A</p><p> LEFT OUTER JOIN ( SELECT COUNT(ID) AS RecCount ,</p><p> MONTH(DateOfBirth) AS MonthNumber</p><p> FROM tempStudent</p><p> GROUP BY MONTH(DateOfBirth)</p><p></p><p><strong>Result</strong></p><p></p><p>MonthName NoOfBirthdays</p><p>January 1</p><p>February 2</p><p>March 0</p><p>April 0</p><p>May 3</p><p>June 0</p><p>July 0</p><p>August 3</p><p>September 1</p><p>October 0</p><p>November 0</p><p>December 0</p></blockquote><p></p>
[QUOTE="sameemail, post: 22634505, member: 24079"] [b]Try This - Works with SQL 2008[/b] [B]Data Set [/B] ID StudentName DateOfBirth 1 saman 2015-01-02 6 thilina 2015-08-10 7 lahiru 2015-08-15 5 nayana 2015-08-25 4 kamal 2015-09-02 2 nimal 2016-02-02 9 kevin 2017-02-20 8 kapila 2017-05-02 3 amal 2017-05-02 10 sirimal 2017-05-22 ---------------------------------------------- [B]Query[/B] --**Need to Enter the year (Any Year) DECLARE @year INT SET @year = 2015 SELECT A.MonthName , ISNULL(B.RecCount,0) AS NoOfBirthdays FROM ( SELECT number AS MonthNumber , DATENAME(MONTH, CAST(@year * 100 + number AS VARCHAR) + '01') AS MonthName FROM master.dbo.spt_values WHERE ( type = 'P' ) AND ( number BETWEEN 1 AND 12 ) ) AS A LEFT OUTER JOIN ( SELECT COUNT(ID) AS RecCount , MONTH(DateOfBirth) AS MonthNumber FROM tempStudent GROUP BY MONTH(DateOfBirth) [B]Result[/B] MonthName NoOfBirthdays January 1 February 2 March 0 April 0 May 3 June 0 July 0 August 3 September 1 October 0 November 0 December 0 [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom