Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all .. i m facing a problem in sql query..

my query is:

SQL
select b.schname from [17CHILD_D] a inner join SCHMAST b on RIGHT(a.sch_code,6)=RIGHT(b.schcode,6) where a.distt=17 and a.block=01 and b.vcode=001

it's not working .. when i remove last condition then records are fetched..

please give me correct syntax..

please help thanks in advance
Posted
Updated 12-Apr-14 0:11am
v2

There is nothing wrong with the syntax per se
That JOIN is awful though ... consider setting up a proper primary key / foreign key relationship

By "it's not working" I take it to mean that it is not returning any results, but that it does return results if you remove and b.vcode=001

Firstly - why the preceding zeroes ... if columns vcode and distt are numeric then write this as
SQL
where a.distt=17 and a.block=1 and b.vcode=1

However if they are char or varchar then write it like this
where a.distt=17 and a.block='01' and b.vcode='001'


After that, if you are still not getting results back then there is no matching data on your table. Run it without that last condition but adding vcode to the SELECT - have a good look at the results, you'll find that none of the records have vcode = 1
 
Share this answer
 
Comments
Manas Bhardwaj 13-Apr-14 13:02pm    
Well explained +5!
Hi Bindash,

Hmm pls check the column does have value "001" or something else.
I think it may have be like .001
 
Share this answer
 
Comments
bindash 14-Apr-14 0:41am    
hii.. thanks for reply... bt i check. it's not working..if i remove any one condition then records are fetched

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