Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
DamithSL 17-Dec-14 22:06pm    
try
EXECUTE usr_sp_Search_palace_by_City_Date @RoomName ='',@CityId =8, @LandMark ='', @BookingDate ='2014-12-13'
or
EXECUTE usr_sp_Search_palace_by_City_Date '',8,'','2014-12-13'

I have executed with

EXECUTE usr_sp_Search_palace_by_City_Date @PalaceName ='',@CityId =8, @LandMark ='', @BookingDate ='2014-12-13'

It is throwing below error:

Msg 102, Level 15, State 1, Line 10
Incorrect syntax near '%2%'.
 
Share this answer
 
Comments
DamithSL 17-Dec-14 22:15pm    
what is line 10? and what is column data type of Pdate?
DamithSL 17-Dec-14 22:19pm    
change
set @Query=@Query+'and tblP.RoomId not in (Select RoomId from tblBookings where Pdate like ''%'+CAST(@BookingDate AS VARCHAR)+'%'''
to
set @Query=@Query+'and tblP.RoomId not in (Select RoomId from tblBookings where CONVERT(VARCHAR, Pdate, 120)
like ''%'+@BookingDate+'%'''
Pdate have varchar datatype"
and Line 10 is "ALTER procedure usr_sp_Search_Room_by_City_Date
 
Share this answer
 
Comments
DamithSL 17-Dec-14 22:30pm    
remove both your solutions, update the question with all the above data, what you have tried and the error you recived. these are not solutions and also note this section in not a forum, only answers can provide as solutions.
I have tried it
Still giving same issue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900