CREATE PROC KY_UsedCar_AdvancedSearch
(
@pinpai varchar(35)=null, --1、品牌
@chexing varchar(30)=null, --2、车型
@nianfen varchar(20)=null, --3、车龄
@cheliangsuozaidi varchar(20)=null, --4、省份
@chengshi varchar(20)=null, --5、城市
@xingshigonglishu int=null, --6、行驶里程
@biansuxiang varchar(20)=null, --7、变速箱类型
@jiage int=null, --8、价格区间
@yanse varchar(10)=null --9、颜色
--10、关键字
)
AS
declare @sqlStr varchar(500)
----品牌
if @pinpai <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and pinpai='+''''+@pinpai+''''
else
set @sqlStr=' where pinpai='+''''+@pinpai+''''
end
/*begin
set @sqlStr=' where pinpai='+''''+@pinpai+''''
end*/
----车型
if @chexing <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and chexing='+''''+@chexing+''''
else
set @sqlStr=' where chexing='+''''+@chexing+''''
end
----车龄
if @nianfen <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and nianfen='+''''+@nianfen+''''
else
set @sqlStr=' where nianfen='+''''+@nianfen+''''
end
----省份
if @cheliangsuozaidi <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and cheliangsuozaidi='+''''+@cheliangsuozaidi+''''
else
set @sqlStr=' where cheliangsuozaidi='+''''+@cheliangsuozaidi+''''
end
----城市
if @chengshi <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and nianfen='+''''+@chengshi+''''
else
set @sqlStr=' where nianfen='+''''+@chengshi+''''
end
----行驶里程
if @xingshigonglishu <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and xingshigonglishu='+''''+@xingshigonglishu+''''
else
set @sqlStr=' where xingshigonglishu='+''''+@xingshigonglishu+''''
end
----变速箱类型
if @biansuxiang <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and biansuxiang='+''''+@biansuxiang+''''
else
set @sqlStr=' where biansuxiang='+''''+@biansuxiang+''''
end
----区间价格
if @jiage <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and jiage='+''''+@jiage+''''
else
set @sqlStr=' where jiage='+''''+@jiage+''''
end
----颜色
if @yanse <>''
begin
if @sqlStr <>''
set @sqlStr=@sqlStr+' and yanse='+''''+@yanse+''''
else
set @sqlStr=' where yanse='+''''+@yanse+''''
end
EXEC('select * from Ky_U_UsedCarResource'+@sqlStr)
GO
浙公网安备 33010602011771号