--matched ans & qans
update qad set res=1
FROM qad a,qusr b
where a.qad=b.qusr
--unmatched ans & qans
update qusr set res=0
FROM qad a,qusr b
where a.qad<>b.qusr
Now after half an hour I again executed same query and now it shows error as :
The query is :
--matched ans & qans
update qusr set res=1
FROM qad a,qusr b
where a.qans=b.uans
--unmatched ans & qans
update qusr set res=0
FROM qad a,qusr b
where a.qans<>b.uans
The error is:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'qad'.
I din't understand the same query worked fine for 1st 3 updates later on it din't update and when I went back to the query section and executed it again and again then after sometim it gives this error.
Why does it happen like this?
IAmateur
Member
96 Points
388 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 08:38 AM|LINK
To be specific its :
Table 1 is qad
Table 2 is qusr
And the fields in qad are qid,qans
And the fields in qusr are qid ,uans,res.
Time to go Long way...
yrb.yogi
Star
14460 Points
2402 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 08:44 AM|LINK
.Net All About
kirupa.v
Contributor
2070 Points
531 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 09:53 AM|LINK
Hi,
No, Only result will get updated...
I am comparing uans and qans..
If both have equal values then the result field will become '1' or it ll be '0'
that s how u have asked for.....
Am i right..
IAmateur
Member
96 Points
388 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 10:10 AM|LINK
Yes I have asked same...
Time to go Long way...
kirupa.v
Contributor
2070 Points
531 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 10:35 AM|LINK
Hi,
Just change the table names and columns names..
U ll get the required out put...
Just chk it in sql server 2008..
IAmateur
Member
96 Points
388 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 10:42 AM|LINK
Kirupa
ya dear I did chng tabl names n col names but stil it dint work out. I am doing this in sql mngmt studio 2005
Time to go Long way...
kirupa.v
Contributor
2070 Points
531 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 10:44 AM|LINK
Hi,
Can u send me the table structure and the script that u have executed..
SO that i can verify and tel u .......
IAmateur
Member
96 Points
388 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 11:00 AM|LINK
Hie just now I wrote the query in this way but it updated the table field res only 3 times after that its not updating.
The query I wrote is :
--matched ans & qans
update qusr set res=1
FROM qad a,qusr b
where a.qans=b.uans
--unmatched ans & qans
update qusr set res=0
FROM qad a,qusr b
where a.qans<>b.uans
As per this it din't give any error and updated the 1st 3 rows correctly but after that all rows As NULL
Time to go Long way...
IAmateur
Member
96 Points
388 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 11:20 AM|LINK
Now after half an hour I again executed same query and now it shows error as :
The query is :
--matched ans & qans
update qusr set res=1
FROM qad a,qusr b
where a.qans=b.uans
--unmatched ans & qans
update qusr set res=0
FROM qad a,qusr b
where a.qans<>b.uans
The error is:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'qad'.
I din't understand the same query worked fine for 1st 3 updates later on it din't update and when I went back to the query section and executed it again and again then after sometim it gives this error.
Why does it happen like this?
Time to go Long way...
yrb.yogi
Star
14460 Points
2402 Posts
Re: How to compare different fields from different tables?
Apr 11, 2012 11:22 AM|LINK
.Net All About