日期:2014-05-19  浏览次数:20491 次

求一条 SQL 语句简化问题
If   @searchBy   = 's_number '     --//   ?看看能否简化
    Select   Students.department   From   Students
    Where   Students.s_number   =   @searchValue
  If   @searchBy   = 'studentName '
    Select   Students.department   From   Students
    Where   Students.studentName   =   @searchValue


能否只是根据这两段进行判断一下:
  Students.s_number   =   @searchValue
  Students.studentName   =   @searchValue

把这段代码,用作一段共享
    Select   Students.department   From   Students
    Where

------解决方案--------------------
Select department
From Students
Where (CASE @searchValue WHEN 's_number ' THEN studentName ELSE department END )=@searchValue