create proc sp_ST_product_getlist1
@city nvarchar(10), --城市
@text nvarchar(50) --输入条件
as
declare @sql nvarchar(500),@where nvarchar(500),@order nvarchar(500)
select @sql='select website, loc, productId, city, category, title, img, startTime, oldprice, endTime, price, rebate, sort, ischeck from ST_product',
@where='',@order=' sort asc'
if @city <> ''
if @where <> ''
set @where = @where+' and (city='+@city+')'
else
set @where = @where+' (city='+@city+')'
if @text <>''
if @where <> ''
set @where = @where+' and ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
else
set @where = @where+' ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
if @where <> ''
set @where =' where'+@where
if @order <> ''
set @order =' order by'+@order
exec(@sql+@where+@order)goexec sp_ST_product_getlist1
'全国','蝶恋' 为什么会提示 列名 '全国' 无效。
@city nvarchar(10), --城市
@text nvarchar(50) --输入条件
as
declare @sql nvarchar(500),@where nvarchar(500),@order nvarchar(500)
select @sql='select website, loc, productId, city, category, title, img, startTime, oldprice, endTime, price, rebate, sort, ischeck from ST_product',
@where='',@order=' sort asc'
if @city <> ''
if @where <> ''
set @where = @where+' and (city='+@city+')'
else
set @where = @where+' (city='+@city+')'
if @text <>''
if @where <> ''
set @where = @where+' and ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
else
set @where = @where+' ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
if @where <> ''
set @where =' where'+@where
if @order <> ''
set @order =' order by'+@order
exec(@sql+@where+@order)goexec sp_ST_product_getlist1
'全国','蝶恋' 为什么会提示 列名 '全国' 无效。
解决方案 »
- 困惑:视图是否降低性能?!
- 如何取一个变量的后两位
- 如何把本地的一个表创建到远程服务器上?
- sqlserver简体数据库结构能否用在繁体上?
- 用SQL2000时,T-sql语句使用时出现了这个,怎么了?
- sql优化,新员工,现在要优化一个项目的sql,就这点分了, 全给了,只希望有满意结果。
- 一个基础问题,请大家帮帮忙吧?
- 高手请指教,这条sql语句如何优化? --在线等待
- 请问:如何设计表?
- Paradox7 to Sql Server?看过李维书的都来看看.没看过的也来。:)
- Response.Write("<script defer>confirm('你确定吗?')</script>")
- 对表数据复制,如何查看相关日志
alter proc sp_ST_product_getlist1
@city nvarchar(10), --城市
@text nvarchar(50) --输入条件
as
declare @sql nvarchar(500),@where nvarchar(500),@order nvarchar(500)
select @sql='select website, loc, productId, city, category, title, img, startTime, oldprice, endTime, price, rebate, sort, ischeck from ST_product',
@where='',@order=' sort asc'
if @city <> ''
if @where <> ''
set @where = @where+' and (city='''+@city+''')' --两边少了单引号
else
set @where = @where+' (city='''+@city+''')' --两边少了单引号
if @text <>''
if @where <> ''
set @where = @where+' and ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
else
set @where = @where+' ((title like ''%'+@text+'%'') or (website like ''%'+@text+'%''))'
if @where <> ''
set @where =' where'+@where
if @order <> ''
set @order =' order by'+@order
exec(@sql+@where+@order)