繁体   English   中英

sql server过程错误

[英]sql server procedure error

CREATE PROCEDURE USP_SEARCH_HOTELS
(
@Text varchar(50),
@Type varchar(40)
)
AS
BEGIN

Declare @Query VARCHAR(60)


IF @Type = 'By Country'
    BEGIN
    SET @Query = 'Hotel.countryName like '+ @Text+'%'
    END
ELSE IF @Type = 'By State'
    BEGIN
    SET @Query = 'HOTEL.stateName like '+ @Text+'%'
    END
ELSE IF @Type='By Property Name'
    BEGIN
    SET @Query='hotel.propertyname like'+ @Text+'%'
    End 
ELSE IF @Type='By Rating'
     BEGIN
     SET @Query='hotel.starRating='+ Cast(@Text as INT)
     END
ELSE IF @Type='By City'
    BEGIN
    SET @Query='hotel.cityName like '+ @Text+'%'
    END

    begin
    select * from hotel,tbl_cust_info
     where
    hotel.agentID=Tbl_Cust_Info.Cust_ID
    and
    (@Query)
    end

END

该程序有什么错误,请帮助。

DECLARE @Final nvarchar(1000)  -- Separate partial and final
DECLARE @Partial nvarchar(100) -- let's you maintain and debug better

SET @Final = 'select * from hotel
join tbl_cust_info 
on hotel.agentID=Tbl_Cust_Info.Cust_ID
where' + @Partial

假设您通过.NET违反了此要求,请对文本运行Regexp以消除所有不是字母或空格的字符。 像[!@#$%^&*()?;:'“ \\ |]。

考虑重写为5个存储过程(HotelsByCountry,HotelsByState,HotelsByCity,HotelsByName,HotelsByRating)。 这将提高您的性能,并让您执行orderby和分页(例如Row_number()OVER(按StartDate排序))。 这也将使它们完全安全。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM