In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Sqlserver in how to get the number of days of the month, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
The copied code is as follows: CREATE FUNCTION [dbo]. [udf_DaysInMonth] (@ Date DATETIME) RETURNS INT AS BEGIN DECLARE @ dim AS TABLE (M INT,Dy INT) INSERT INTO @ dim VALUES (1 dim VALUES), (3) 31), (5) 31), (7) 31), (8) 31), (10), (12) 31), (4) 30), (6) 30), (9) 30), (11) 30), (2) CASE WHEN (YEAR (@ Date)% 4 = 0 AND YEAR (@ Date)% 100) OR (YEAR (@ Date)% 400 = 0) THEN 29 ELSE 28 END) DECLARE @ RValue INT SELECT @ RValue = [Dy] FROM @ dim WHERE [M] = MONTH (@ Date) RETURN @ RValue END GO
Get the number of days of the month, which has been written on the blog before, but it only gets the number of days in February. The link is as follows: http://www.cnblogs.com/insus/articles/2025019.html now sees this function in the project at first sight, and always feels that it is not well written, and whether it can be rewritten better, the heuristic point is also remembered by the CASE function that gets the number of days in February. So, I tried to change it, as follows: the copy code is as follows: CREATE FUNCTION [dbo]. [udf_DaysInMonth] (@ Date DATETIME) RETURNS INT AS BEGIN RETURN CASE WHEN MONTH (@ Date) IN (1min3, 5, 7, 8, 10, 12) THEN 31 WHEN MONTH (@ Date) IN (4, 6, 10, IN) THEN 30 ELSE CASE WHEN (YEAR (@ Date)% 4 = 0 AND YEAR (@ Date)% 100) OR (YEAR (@ Date)% 400 = 0) THEN 29 ELSE 28 END END END 28
If you have already quoted Insus.NET 's custom function to get the number of days in February, you can also refer to the following version: the copy code is as follows: CREATE FUNCTION [dbo]. [udf_DaysInMonth] (@ Date DATETIME) RETURNS INT AS BEGIN RETURN CASE WHEN MONTH (@ Date) IN (THEN 31 WHEN MONTH (@ Date) IN) THEN 30 ELSE [dbo]. [DaysOfFebruary] (YEAR (@ Date)) END END
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.