Skip to content
Loading
How To Bind 3 Table
  • Sachin Singh
    Suppose you have a textbox where you can enter employee name or Id and it should return employee's all information including CheckIn time and CheckOut time then your Stored Procedure should be
    1. create procedure SpGetEmployee  
    2. @searchText Varchar(500)=''  
    3. as  
    4. begin  
    5.   
    6. select * from   
    7.  tbl_Employee e   
    8. JOIN With (NoLock)  
    9.  tbl_CheckIn ci With (NoLock)  
    10. ON  e.Id=ci.EmpId  
    11. JOIN  With (NoLock)  
    12.  tbl_CheckOut co With (NoLock)  
    13. ON co.EmpId=e.Id  
    14. where   
    15. AND 1 = (  
    16. CASE  
    17. WHEN (  
    18. @searchText IS NULL  
    19. OR LEN(@searchText) <= 0  
    20. )  
    21. THEN 1  
    22. ELSE (  
    23. CASE  
    24. WHEN (  
    25. (CAST(e.Id AS VARCHAR(50)) LIKE '%' + @searchText + '%')  
    26.   
    27. OR (EmpName LIKE '%' + @searchText + '%')  
    28.   
    29.   
    30. )  
    31. THEN 1  
    32. ELSE 0  
    33. END  
    34. )  
    35. END  
    36. )  
    37.   
    38. end