3个都赋值“请选择”时,if @t <>'' begin set @s1 = ' select * into t from add_Safe where '+substring(@t,5,4000) end 经过上面的判断,没有生成表t, 所以在下面的select t.*,case when exists(select 1 from planadmin where file_ not in ('陕计投资[2000] 1085号','陕计投资[2001] 148号','陕计投资[2001] 983号','陕计投资[2002] 229号','陕计投资[2002] 596号','陕计投资[2002] 914号','陕计投资[2002] 1176号','陕计投资[2003] 741号','陕计投资[2004] 234号','陕计投资[2004] 441号','陕发改投资[2004] 777号') and city_name = t.F18 and county_name = t.F19 and charindex(t.F20,'、'+retwo+',') >0 and pro_name is not null and construct_spot is not null )then 1 else 0 end as keyid, case when exists(select 1 from planadmin where file_ not in ('陕计投资[2000] 1085号','陕计投资[2001] 148号','陕计投资[2001] 983号','陕计投资[2002] 229号','陕计投资[2002] 596号','陕计投资[2002] 914号','陕计投资[2002] 1176号','陕计投资[2003] 741号','陕计投资[2004] 234号','陕计投资[2004] 441号','陕发改投资[2004] 777号') and city_name = t.F18 and county_name = t.F19 and charindex(t.F20,'、'+retwo+',') >0 and watersupply_population > t.F3 and pro_name is not null and construct_spot is not null)then 1 else 0 end as keyid1 from t where t.F2 is not null and t.F3 is not null 中,也就不存在表t,进而出现了上面的错误
抱错的意思好像是找不到表t,我如果给这3个变量至少赋值一个,则可以得到正确的结果,但是如果我在页面上没有选择条件,则给他们从页面传的值为“请选择”,我在sql中已经写了case when @F18 <>'请选择' then ' and F18 = ''' + @F18 + '''' else '' end ,但为何还是找不到表t呢??应怎样修改上面的语句,使得能不赋条件,查出全部的结果
begin
set @s1 = ' select * into t from add_Safe where '+substring(@t,5,4000)
end 经过上面的判断,没有生成表t,
所以在下面的select t.*,case when exists(select 1 from planadmin where file_ not in ('陕计投资[2000] 1085号','陕计投资[2001] 148号','陕计投资[2001] 983号','陕计投资[2002] 229号','陕计投资[2002] 596号','陕计投资[2002] 914号','陕计投资[2002] 1176号','陕计投资[2003] 741号','陕计投资[2004] 234号','陕计投资[2004] 441号','陕发改投资[2004] 777号') and city_name = t.F18 and county_name = t.F19 and charindex(t.F20,'、'+retwo+',') >0 and pro_name is not null and construct_spot is not null )then 1 else 0 end as keyid,
case when exists(select 1 from planadmin where file_ not in ('陕计投资[2000] 1085号','陕计投资[2001] 148号','陕计投资[2001] 983号','陕计投资[2002] 229号','陕计投资[2002] 596号','陕计投资[2002] 914号','陕计投资[2002] 1176号','陕计投资[2003] 741号','陕计投资[2004] 234号','陕计投资[2004] 441号','陕发改投资[2004] 777号') and city_name = t.F18 and county_name = t.F19 and charindex(t.F20,'、'+retwo+',') >0 and watersupply_population > t.F3 and pro_name is not null and construct_spot is not null)then 1 else 0 end as keyid1
from t where t.F2 is not null and t.F3 is not null 中,也就不存在表t,进而出现了上面的错误