tags:

views:

21

answers:

1

My following sql query giving me the following error, What does it mean. Am i defining the alias fir column in wring way. Please help me out with this. My error is this and i am putting query just below the error.

Error in SELECT clause: expression near 'Year'.
Missing FROM clause.
Unable to parse query text.



SELECT [tbl_students].passing_year as Passing Year,[tbl_branch].branch_name as Branch_Name FROM [tbl_students], [tbl_course], [tbl_branch] WHERE [tbl_students].course_id=@courseId 
                        AND   [tbl_students].branch_id IN(64) 
                        AND   [tbl_students].course_id=[tbl_course].course_id AND [tbl_students].branch_id=[tbl_branch].branch_id                        
                        AND  (@firstYrPercent is null OR [tbl_students].first_year_percent>=@firstYrPercent)
                        AND  (@secondYrpercent is null OR [tbl_students].second_year_percent>=@secondYrPercent)
                        AND  (@thirdYrPercent is null OR[tbl_students].third_year_percent>=@thirdYrPercent)
                        AND  (@finalYearpercent is null OR [tbl_students].final_year_percent>=@finalYearpercent)
                        AND  (@currentDegeePercentage is null OR [tbl_students].current_degree_percent>=@currentDegeePercentage)
                        AND  (@passoutYear is null OR [tbl_students].passing_year>=@passoutYear) 
                        AND  (@currentBacklog is null OR [tbl_students].current_backlog=@currentBacklog)
                        AND  (@sex is null OR [tbl_students].gender=@sex) 
                        AND  (@eGap is null OR [tbl_students].gapin_education<=@eGap)
                        AND  (@highSchoolPercentge is null OR [tbl_students].highschool_percentage>=@highSchoolPercentge)
                        AND  (@higherSchoolPercentage is null OR [tbl_students].ssc_percentage>=@higherSchoolPercentage)
                        AND  (@grauationPercentage is null OR [tbl_students].graduation_percentage>=@grauationPercentage)
                        AND  (@diplomaPercentage is null OR [tbl_students].diploma_percentage>=@diplomaPercentage)
                        AND  (@noOfAtkt is null OR [tbl_students].number_of_ATKT<=@noOfAtkt)
                        AND  (@validDate is null OR [tbl_students].DOB>=@validDate)
+1  A: 

You need to escape your Passing Year column with square brackets (see first line):

SELECT [tbl_students].passing_year as [Passing Year],
       [tbl_branch].branch_name    as Branch_Name 
FROM  [tbl_students], [tbl_course], [tbl_branch] 
WHERE [tbl_students].course_id=@courseId 
AND   [tbl_students].branch_id IN(64) 
AND   [tbl_students].course_id=[tbl_course].course_id AND [tbl_students].branch_id=[tbl_branch].branch_id                        
AND  (@firstYrPercent is null OR [tbl_students].first_year_percent>=@firstYrPercent)
AND  (@secondYrpercent is null OR [tbl_students].second_year_percent>=@secondYrPercent)
AND  (@thirdYrPercent is null OR[tbl_students].third_year_percent>=@thirdYrPercent)
AND  (@finalYearpercent is null OR [tbl_students].final_year_percent>=@finalYearpercent)
AND  (@currentDegeePercentage is null OR [tbl_students].current_degree_percent>=@currentDegeePercentage)
AND  (@passoutYear is null OR [tbl_students].passing_year>=@passoutYear) 
AND  (@currentBacklog is null OR [tbl_students].current_backlog=@currentBacklog)
AND  (@sex is null OR [tbl_students].gender=@sex) 
AND  (@eGap is null OR [tbl_students].gapin_education<=@eGap)
AND  (@highSchoolPercentge is null OR [tbl_students].highschool_percentage>=@highSchoolPercentge)
AND  (@higherSchoolPercentage is null OR [tbl_students].ssc_percentage>=@higherSchoolPercentage)
AND  (@grauationPercentage is null OR [tbl_students].graduation_percentage>=@grauationPercentage)
AND  (@diplomaPercentage is null OR [tbl_students].diploma_percentage>=@diplomaPercentage)
AND  (@noOfAtkt is null OR [tbl_students].number_of_ATKT<=@noOfAtkt)
AND  (@validDate is null OR [tbl_students].DOB>=@validDate)
Dave Markle