Ganesh babu

Ganesh babu

  • NA
  • 40
  • 3k

How to search grid view using date column?

Apr 26 2019 8:51 AM
 In a SQL Server database, I have a table Priority with 3 columns id, name and registered date. For registered date, default value is getdate()which automatically generates the record created date and time. Now in grid view, I want to search records using this registered date.In grid view, I have dropdown search by using name and date.
  1. CREATE PROCEDURE [dbo].[SEARCHPRIOR]  
  2. @SearchBy VARCHAR(50),  
  3. @SearchVal VARCHAR(50),  
  4. AS  
  5. BEGIN  
  6. IF @SearchBy = '1'  
  7. BEGIN  
  8. SELECT * FROM PRIORITY WHERE P_NAME LIKE '%' + @SearchVal + '%'  
  9. END  
  10. ELSE IF @SearchBy = '2'  
  11. BEGIN  
  12. SELECT * FROM PRIORITY WHERE P_TS LIKE '%' + @SearchVal + '%'  
  13. END  
  14. ELSE  
  15. BEGIN  
  16. SELECT * FROM PRIORITY   
  17. END  
  18. END  
I have tried searching with this query but getting no results found in grid view. This is how table look like in SQL Server:
 
P_ID     P_NAME     P_TS
-------------------------------------------
1         High      2019-04-23 16:17:08.097
2         Medium    2019-04-24 16:17:23.070
3          Low      2019-04-25 16:17:32.420 

Answers (4)