if date is given display data based on date other wise all record in select query
Loading
if date is given display data based on date other wise all record in select query
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyaprakash SamantarayPosted Jan 3, 2024, 8:30 AM
https://www.c-sharpcorner.com/article/filter-records-based-on/
Naimish MakwanaPosted Jan 3, 2024, 7:44 AM
Hello Lejo,
Try below query.
Thanks
Jayraj ChhayaPosted Jan 3, 2024, 5:50 AM
To display data based on a specific date in a SQL SELECT query, you can use the WHERE clause to filter the records. If a date is given, you can specify the date condition in the WHERE clause. If no date is given, you can omit the date condition, and the query will return all records.
Here's an example of how you can achieve this in SQL:
Anandu G NathPosted Jan 3, 2024, 5:25 AM
You can achieve this in SQL by using a conditional
WHEREclause to filter records based on a given date or show all records if no date is provided.SELECT *
FROM your_table
WHERE
(your_date_column = @given_date OR @given_date IS NULL)
OR
(@given_date IS NULL) -- Include this condition to show all records when no date is given
Jignesh KumarPosted Oct 27, 2023, 10:06 AM
Hi Lejo,
You can use this query to get conditional date filter, Pass your date parameter null then use below query
Uday DodiyaPosted Oct 27, 2023, 9:13 AM
Hi lejo,
Use the following query
If your parameter value is NULL, then it returns all records. For example,
Vishal JoshiPosted Oct 27, 2023, 8:59 AM
Hello Lejo,
You can achieve the task by writing the stored procedure or if it's in code you can write a dynamic query. please find the below SQL server code to get the result.
Thanks
Vishal Joshi