Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai this is my sql server table.. Please chek it.

Articleid(int) ArticleTitle(varchar) CreatedDate(datetime)

1 Test1 2013-09-06 16:18:48.107

2 Test2 2013-10-06 16:34:50.000




Hai this is my table... Here i want to find out the Article Titles Based on the month...

Can any one help me how to write the stored procedure for this one.
Posted

You could use the MSSQL server built in MONTH Function.

Something like this should work:
SQL
SELECT * FROM TableName WHERE MONTH(CreatedDate) = 10;


or if you want to query based on year and month:

SQL
SELECT * FROM TableName WHERE YEAR(CreatedDate) = 2013 AND MONTH(CreatedDate) = 10;


... hope it helps.

[EDIT]
To query by specifying a month name, (which is not as an efficient solution compared with querying by month number), have a look at the MSSQL server built in DATENAME Function.

Something like this should get you started:
SQL
SELECT * FROM TableName WHERE DATENAME(month, CreatedDate) = 'october';
 
Share this answer
 
v2
SQL
declare @month varchar(50)
set @month = 'january';

set @month = @month + ' 01 2000'; -- dummy line (don't bother about 01 2000 )
select  @month = DATEPART(MM,@month)
set @month = RIGHT('0' + @month,2)
print @month
SELECT * FROM TableName  WHERE ArticleTitle LIKE '%-' +@month + '-%';
 
Share this answer
 
v3
Comments
kanth5865 8-Jan-14 7:05am    
Hai karthik i just want to find the article title using month name like august,september
Karthik_Mahalingam 8-Jan-14 7:07am    
ok kanth.. wait.
Karthik_Mahalingam 8-Jan-14 7:19am    
try my updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900