Hi Friends, I have created below store procedure
ALTER procedure usr_sp_Search_Room_by_City_Date ----'','8','','DEC 13 2014'
@RoomName varchar(100),
@CityId int=0,
@LandMark varchar(100),
@BookingDate varchar
as
begin
Declare @Query as varchar(max)
set @Query='Select tblusr.UserId,tblP.RoomId,tblP.LandMark,tblusrL.Role,tblusr.UserFname,tblusr.UserLname,tblusr.UserPhNo,
tblusr.Gender,tblP.RoomName,tblCountry.CntryId,tblCountry.CntryName,tblState.StateId,tblState.StateName,
tblCity.CityId,tblCity.CityName,tblP.RoomPrice,tblP.PTotalSeating,tblP.PAc_NonAc,tblP.RoomPhNo,tblP.RoomTypeId,
tblRoomType.RoomType,tblP.GoogleLink,tblP.ParkingSpace,tblP.Accomodation,tblP.HallArea,tblP.BookingAmount,
tblP.RoomLandLine,tblP.Zip,tblImg.ImageName
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(@RoomName!=' ')
set @Query=@Query + ' and tblP.RoomName like ''%'+@RoomName+'%'''
if(@LandMark!=' ')
set @Query=@Query + ' and tblP.LandMark like ''%'+@LandMark+'%'''
if(@CityId!=' ')
set @Query=@Query + ' and tblCity.CityId='+cast(@CityId as varchar)
if(@BookingDate!=' ')
set @Query=@Query+'and tblP.RoomId not in (Select RoomId from tblBookings where Pdate like ''%'+CAST(@BookingDate AS VARCHAR)+'%'''
exec(@Query)
end
Whenever I have tried to run this store procedure
Command :
usr_sp_Search_Room_by_City_Date '','8','','DEC 13 2014'
It is throwing below error :
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '%D%'.
usr_sp_Search_palace_by_City_Date '','8','','12-13-2014'
It is throwing below error :
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '%1%'.
Pdate have datatype.
Please help me to get rid of this issue.