SQL查询错误

时间:2010-08-17 05:34:13

标签: sql

  

可能重复:
  please correct me with the sql query

给出下面提到的错误,所以请在此处纠正我

Msg 137,Level 15,State 2,Line 1 必须声明标量变量“@courseId”。

@"SELECT * FROM [tbl_students] WHERE course_id=@courseId AND branch_id IN("+branchId+@") 
                AND (@passoutYear is null OR passing_year>=@passoutYear) 
               AND  (@currentBacklog is null OR current_backlog<=@currentBacklog)
AND  gender=@sex AND (@eGap is null OR gapin_education<=@egap)
AND  (@firstYrPercent is null OR first_year_percent>=@firstYrPercent
AND  (@secondYrpercent is null OR second_year_percent>=@secondYrPercent)
AND  (@thirdYrPercent is null OR third_year_percent>=@thirdYrPercent)
AND  (@finalYrpercent is null OR final_year_percent>=@finalYrpercent)
AND  (@currentDegreePercentage is null OR current_degree_percent>=@currentDegreePercentage)
AND  (@highSchoolPercentage is null OR highschool_percentage>=@highSchoolPercentage)
AND  (@higherSchoolPercentage is null OR ssc_percentage>=@higherSchoolPercentage)
AND  (@graduationPercent is null OR graduation_percentage>=@graduationPercentage)
AND  (@diplomaPercentage is null OR diploma_percentage>=@diplomaPercenage)
AND  (@noOfAtkt is null OR number_of_ATKT<=@noOfAtkt)
AND  (@date is null OR DOB>=@date)"

2 个答案:

答案 0 :(得分:0)

这只是意味着您忘记为SqlParameter为您的命令创建@courseId值。

答案 1 :(得分:0)

你有:

  • 未在SQL查询中声明变量@courseId
  • 未向存储过程
  • 声明参数