Click here to Skip to main content
15,908,673 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hii all.. i m getting error in my sql stored procedure.. plz help

my sp's query is:

SQL

   SET @vQuery ='SELECT Child.gpmctc as gpmctc,Child.village as village ,Child.habitation as habitation,
 Child.cname as cname, Child.sex as sex,Child.dob as dob,Child.sch_code as sch_code,Child.class as class,
 Child.nereason as nereason,Child.droupout as droupout,Child.highclass as highclass
    FROM ' + @ChildTblName + ' As Child   
    WHERE  Child.distt = ' + @DistrictID + ' and   LTRIM(RTRIM(ISNULL(sch_code,'')))='' and  Child.block=' + @blockcode + ' and age>=6 and age<=14' 



error:Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'and'.

plz help thanks in advance
Posted
Updated 21-Apr-14 20:57pm
v2
Comments
Herman<T>.Instance 22-Apr-14 2:59am    
USING MSSQL ? TIP: and age between 6 and 14
Abhinav S 22-Apr-14 3:09am    
Well that won't solve the error.
Herman<T>.Instance 22-Apr-14 3:17am    
true, that is why it is a tip. Makes the query more readable
Abhinav S 22-Apr-14 3:19am    
Fair enough. Its a good tip.

,'')))=''
There are two quotes here.
Try ,'')))=' .
 
Share this answer
 
Comments
Herman<T>.Instance 22-Apr-14 2:58am    
he compares '', therefore two '
bindash 22-Apr-14 3:04am    
thanks for give solution.. bt it's not working
Abhinav S 22-Apr-14 3:10am    
Sorry. Try ,'')))=''''
Hi,
Please check the below query, and let me know if it helps.
SET @vQuery ='SELECT Child.gpmctc as gpmctc,Child.village as village ,Child.habitation as habitation,
 Child.cname as cname, Child.sex as sex,Child.dob as dob,Child.sch_code as sch_code,Child.class as class,
 Child.nereason as nereason,Child.droupout as droupout,Child.highclass as highclass
    FROM ' + @ChildTblName + ' As Child   
    WHERE  Child.distt = ' + @DistrictID + ' and   LTRIM(RTRIM(ISNULL(sch_code,'''')))='''' and  Child.block=' + @blockcode + ' and age>=6 and age<=14' 


Thanks,
Hitesh Varde
 
Share this answer
 
v2
Comments
bindash 22-Apr-14 3:08am    
thanks.. but it's not working..
bindash 23-Apr-14 4:44am    
sorry .. it's working fine.. and thanks..
Hitesh Varde 22-Apr-14 3:10am    
SET @vQuery ='SELECT Child.gpmctc as gpmctc,Child.village as village ,Child.habitation as habitation,
Child.cname as cname, Child.sex as sex,Child.dob as dob,Child.sch_code as sch_code,Child.class as class,
Child.nereason as nereason,Child.droupout as droupout,Child.highclass as highclass
FROM ' + @ChildTblName + ' As Child
WHERE Child.distt = ' + @DistrictID + ' and LTRIM(RTRIM(ISNULL(sch_code,'''')))='''' and Child.block=' + @blockcode + ' and age>=6 and age<=14'
Try Replacing LTRIM(RTRIM(ISNULL(sch_code,'')))='' with LTRIM(RTRIM(ISNULL(sch_code,'''')))=''''
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900