title: How to pass a date parameter into a stored procedure
body: <p>I have created a stored procedure for booking rooms that are not in the <code>tblBooking</code> table for the date which is passing in as a parameter.</p>
  
  <p><code>Pdate</code> is of type <code>varchar</code></p>
  
  <p>When I try to run this stored procedure with the command:</p>
  
  <pre><code>usr_sp_Search_Room_by_City_Date '','8','','DEC 13 2014'
  </code></pre>
  
  <p>It is throws this error:</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 10<br>
    Incorrect syntax near '%D%'.</p>
  </blockquote>
  
  <p>Here is my procedure:</p>
  
  <pre><code>ALTER procedure usr_sp_Search_Room_by_City_Date 
      @RoomName varchar(100),
      @CityId int = 0,
      @LandMark varchar(100),
      @BookingDate varchar
  as
  begin
     Declare @Query as varchar(max)
  
     set @Query = 'Select * from tblUser tblusr 
                   join tblUserLogIn tblusrL on tblusr.UserId = tblusrL.UserId
                   join tblRoom tblP on tblP.RoomId = tblusr.UserId 
                   join tblImage tblImg on tblImg.RoomId = tblusr.UserId 
                   join tblCountry on tblP.RoomCountryId = tblCountry.CntryId 
                   join tblState on tblState.StateId = tblP.RoomStateId
                   join tblCity on tblCity.CityId = tblP.RoomCityId 
                   join tblRoomType on tblRoomType.RoomTypeId = tblP.RoomTypeId
                   where ''true''=tblImg.IsProfileImage and ''true''=tblusrL.Isconfirmed'
  
     if(@BookingDate != ' ')
        set @Query=@Query+'and tblP.RoomId not in (Select RoomId from tblBookings 
  
     where Pdate like ''%'+CAST(@BookingDate AS VARCHAR)+'%'''
  
     exec(@Query)
  
  end 
  </code></pre>