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
'全国','蝶恋' 为什么会提示  列名 '全国' 无效。

解决方案 »

  1.   


    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)
      

  2.   

    PTINT 印出来你的单引号对不对  
      

  3.   

    检查存储过程的方法一般是 print出来看看 错误在哪里