急需帮助。

应该死在键盘上 2013-09-24 08:07:12
从前台得到参数到后台,在后台作为检索select的where判断条件。比如前台是学生id,学生name,
后台就应该是select * from Student where student_id = @p_student_id and student_name = @p_student_name, 请问 如果前台没有输入student_id 是空,传进来的参数就是''怎么在procedure里做这个判断如果 参数是空的时候,怎么用if 判断parameter是空的情况,谢谢各位大神,小弟是新手。
...全文
97 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
天空丶蒋 2013-09-24
  • 打赏
  • 举报
回复
请问能判断一下值吗?? string sql="select * from Student where 0=0" if(id!="") { sql+= " and student_id = "+ id; } if(name!="") { sql+= " and student_name"+name; }
全栈极简 2013-09-24
  • 打赏
  • 举报
回复
存储过程么? 定义个in变量比如p_student_id,然后直接判断 if p_student_id='' then ... 就可以了。 类似:
declare @tempSql varchar(4000);
    set @tempSql =' select used_amount,month_1,month_2,month_3,month_4,
    month_5,month_6,month_7,month_8,month_9,month_10,month_11,month_12 
    from #temp where 1=1 ';
    if(@city <>'' and @city <>'0')
	  set @tempSql += ' and city in '+@city+'';
  • 打赏
  • 举报
回复
现在有人在吗?
  • 打赏
  • 举报
回复
希望得到你们的帮助,谢谢

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧