Order by Current MonthYKyesubabu k8yAsked Aug 12, 2018, 8:24 PM EDT7 answersShareLinkedInXCopy linkSaveDear Sir , how to show data in sql server 2005 order by current month Like Augsepoct......
Order by Current MonthYKyesubabu k8yAsked Aug 12, 2018, 8:24 PM EDT7 answersShareLinkedInXCopy linkSaveDear Sir , how to show data in sql server 2005 order by current month Like Augsepoct......
MVManikandaprabu V49 reputation8y agoPosted Aug 12, 2018, 8:31 PM EDT+1SELECT DateFieldFROM TableORDER BY DateField -- this give month wise and day wise+1
Jenith ThakkarRank #789 · 2.9K reputation8y agoPosted Aug 12, 2018, 8:31 PM EDT+1Will you please provide your table structure+1
Rajeesh MenothRank #118 · 18.4K reputation8y agoPosted Aug 12, 2018, 9:08 PM EDT+1Hi, As a beginner you can read the following article : https://www.w3schools.com/sql/sql_orderby.asp+1
Pravat KumarRank #2,456 · 573 reputation8y agoPosted Aug 12, 2018, 9:19 PM EDT+1Hello Yesubabu, Please use the below query, that might solve your problem. CREATE FUNCTION fn_MonthNameToMonthNumber (@monthName VARCHAR(20)) RETURNS INT AS BEGIN DECLARE @monthNumber AS INT; SELECT @monthNumber = CASE @monthName WHEN 'January' THEN 1 WHEN 'February' THEN 2 WHEN 'March' THEN 3 WHEN 'April' THEN 4 WHEN 'May' THEN 5 WHEN 'June' THEN 6 WHEN 'July' THEN 7 WHEN 'August' THEN 8 WHEN 'September' THEN 9 WHEN 'October' THEN 10 WHEN 'November' THEN 11 WHEN 'December' THEN 12 END RETURN @monthNumber END select Name,Age,Salary,dbo.fn_MonthNameToMonthNumber(MONTH) as MonthNO Into #tempTable from Yourtable where (yourCondition) select Name,Age,Salary from #tempTable order by MonthNO ASC|DESC+1Rafnas T PRank #280 · 8.8K reputation8y agoPosted Aug 13, 2018, 12:13 AM EDT+1hi, try as follows SELECT DateFieldFROM TableORDER BY month(DateField)+1Yogesh GhorpadeRank #2,756 · 509 reputation8y agoPosted Aug 13, 2018, 12:49 AM EDT+1Select Field 1,Field 2,Field 3,Field 4 From TableName Where If Any Cindition Order By month(getdate())+1Ronika JencyRank #770 · 3K reputation8y agoPosted Aug 14, 2018, 3:24 AM EDT+1 Hi, Table Name: userdetails Table Structure Table data: Query, you asked select left(convert(varchar,datename(month,DOB),100),3)From userdetails Order By Case When month(DOB) < month(GetDate()) Then month(DOB) +12ELSE month(DOB) END Result Sample Query Format: select datename(month,ColumnName)From TableName Order By Case When month(ColumnName) < month(GetDate()) Then month(ColumnName) +12ELSE month(ColumnName) END+1Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rafnas T PRank #280 · 8.8K reputation8y agoPosted Aug 13, 2018, 12:13 AM EDT+1hi, try as follows SELECT DateFieldFROM TableORDER BY month(DateField)+1
Yogesh GhorpadeRank #2,756 · 509 reputation8y agoPosted Aug 13, 2018, 12:49 AM EDT+1Select Field 1,Field 2,Field 3,Field 4 From TableName Where If Any Cindition Order By month(getdate())+1
Ronika JencyRank #770 · 3K reputation8y agoPosted Aug 14, 2018, 3:24 AM EDT+1 Hi, Table Name: userdetails Table Structure Table data: Query, you asked select left(convert(varchar,datename(month,DOB),100),3)From userdetails Order By Case When month(DOB) < month(GetDate()) Then month(DOB) +12ELSE month(DOB) END Result Sample Query Format: select datename(month,ColumnName)From TableName Order By Case When month(ColumnName) < month(GetDate()) Then month(ColumnName) +12ELSE month(ColumnName) END+1
Manikandaprabu V49 reputationPosted Aug 12, 2018, 8:31 PM EDT
Jenith ThakkarRank #789 · 2.9K reputationPosted Aug 12, 2018, 8:31 PM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Aug 12, 2018, 9:08 PM EDT
Pravat KumarRank #2,456 · 573 reputationPosted Aug 12, 2018, 9:19 PM EDT
Rafnas T PRank #280 · 8.8K reputationPosted Aug 13, 2018, 12:13 AM EDT
Yogesh GhorpadeRank #2,756 · 509 reputationPosted Aug 13, 2018, 12:49 AM EDT
Ronika JencyRank #770 · 3K reputationPosted Aug 14, 2018, 3:24 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts