Right, this is a duplicate post. XuDong Peng provided a C# sample and you marked the answer as solved! At least, click the link so you know what you're refuting.
IMHO, the main problem is your SQL design is poor. This has been explained across many threads but you continue to make these poor design choices. The easiest fix is normalizing the table design. In this case add 4 columns to hold month and day integer
values. Then you don't have to create complex code to fix the poor design.
Below is SQL example but it breaks down if the table can contain multiple years.
IF OBJECT_ID('tempdb..#PoorTableDesign') IS NOT NULL
DROP TABLE #PoorTableDesign
CREATE TABLE #PoorTableDesign (Field1 VARCHAR(1), Ranges VARCHAR(64))
INSERT INTO #PoorTableDesign (Field1, Ranges)
VALUES ('A', '16-Mar - 23-Mar'),
('B', '24-Mar - 30-May'),
('C', '01-Jun - 15-Jun')
DECLARE @Filter DATETIME = CONVERT(DATETIME, '15-Jun-1900', 106)
SELECT Field1,
Ranges
FROM #PoorTableDesign
WHERE @Filter BETWEEN
CONVERT(DATETIME, RTRIM(LEFT(Ranges, 6) + '-1900'), 106)
AND CONVERT(DATETIME, LTRIM(RIGHT(Ranges, 6) + '-1900'), 106)
Member
293 Points
676 Posts
Filter Record With Day & Month
Jun 16, 2020 01:05 PM|Gopi.MCA|LINK
Hello
This is my table data
1) If user pass any date between this ranges has to show desire out put for example if i pass 27-Mar
then it has to show B
2) If user pass any date between this ranges has to show desire out put for example if i pass 19-Mar
then it has to show A
How to do so...
All-Star
123252 Points
10024 Posts
Moderator
Re: Filter Record With Day & Month
Jun 16, 2020 02:59 PM|limno|LINK
https://forums.asp.net/t/2167867.aspx?Filter+Data+Based+On+Given+Date+Input
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
Member
293 Points
676 Posts
Re: Filter Record With Day & Month
Jun 16, 2020 03:05 PM|Gopi.MCA|LINK
Hello
Thanks But This Time Data is in Ranges Without year example like below
16-Mar - 23-Mar
24-Mar - 30-May
01-Jun - 15-Jun
That Code Not Work Use..
Thanking You
All-Star
53021 Points
23604 Posts
Re: Filter Record With Day & Month
Jun 16, 2020 03:22 PM|mgebhard|LINK
This is a duplicate post. You marked the previous post as answered; https://forums.asp.net/p/2168125/6308581.aspx?Filter+Without+Year
Member
293 Points
676 Posts
Re: Filter Record With Day & Month
Jun 23, 2020 12:40 PM|Gopi.MCA|LINK
Hello
Table fields dont have year only date and month
his is my table data
1) If user pass any date between this ranges has to show desire out put for example if i pass 27-Mar
then it has to show B
All-Star
53021 Points
23604 Posts
Re: Filter Record With Day & Month
Jun 23, 2020 01:40 PM|mgebhard|LINK
Right, this is a duplicate post. XuDong Peng provided a C# sample and you marked the answer as solved! At least, click the link so you know what you're refuting.
IMHO, the main problem is your SQL design is poor. This has been explained across many threads but you continue to make these poor design choices. The easiest fix is normalizing the table design. In this case add 4 columns to hold month and day integer values. Then you don't have to create complex code to fix the poor design.
Below is SQL example but it breaks down if the table can contain multiple years.