Whats wrong wrong with this query please correct me on this syntactcally it's going wrong please correct me on this how to concatenate this
string cmd = "SELECT *
FROM [tbl_students]
WHER开发者_开发知识库E course_id=@courseId
AND branch_id IN ("+branchId+")
AND (@passoutYear is null or passout_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_yea_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 current_degree_percent>=@currentDegreePercentage)
AND (@highSchoolPercentage is null high_school_percentage>=@highSchoolPercentage)
AND (@higherSchoolPercentage is null higher_school_percentage>=@higherSchoolPercentage)
AND (@graduationPercent is null graduation_percent>=@graduationPercentage)
AND (@diplomaPercentage is null diploma_percentage>=@diplomaPercenage)
AND (@noOfAtkt is null or no_of_atkt<=@noOfAtkt)
AND (@date is null or date_of_birth>=@date)";
First, if branchId
is a string, then you'll need these single quotes:
branch_id IN('"+branchId+"') AND
though I don't understand why it's not parameterized like so:
branch_id = @branchId AND
Second, you may have misspelled the word 'year' in this field name:
AND (@firstYrPercent is null or first_year_percent>=@firstYrPercent
Finally, you're missing a few OR's here:
AND (@currentDegreePercentage is null OR current_degree_percent>=@currentDegreePercentage)
AND (@highSchoolPercentage is null OR high_school_percentage>=@highSchoolPercentage)
AND (@higherSchoolPercentage is null OR higher_school_percentage>=@higherSchoolPercentage)
AND (@graduationPercent is null OR graduation_percent>=@graduationPercentage)
AND (@diplomaPercentage is null OR diploma_percentage>=@diplomaPercenage)
I think I got it.
Are you getting an error while trying to COMPILE the code, as opposed to running the SQL query?
I'm going to bet that you're using C#, and that you should do multi-line strings with an @-symbol before the "-symbol. Such as this:
string blabla = @"
hello
there
";
Then of course you need it also when you open up the string after branchId
精彩评论