November 9, 2008 at 6:02 am
create table s(sid int, sno int)
create table t(sid int, sno int)
insert into s(sid,sno) values (1,1001)
insert into s(sid,sno) values (2,1002)
insert into s(sid,sno) values (3,1003)
insert into s(sid,sno) values (4,1004)
insert into t(sid,sno) values (1,1001)
insert into t(sid) values (2)
insert into t(sid) values (3)
insert into t(sid) values (4)
now am trying to update all the sno column in t
--Query
update t set t.sno=
(select s.sno from t,s where s.sid=t.sid and t.sno is null)
where t.sno is null and t.sid=s.sid
am getting the following error
--error
Msg 4104, Sevel 16, State 1, Line 1
The multi-part identifier on s.sid could not be bound
Please help me where i shall need to correct the query above.
--Thank You
Chaitanya
November 9, 2008 at 11:47 am
First this clause of your statement:
select s.sno from t,s where s.sid=t.sid and t.sno is null
will return more than a single value, this then yieds the error
Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, = or when the subquery is used as an expression.
The statement has been terminated.
November 9, 2008 at 12:22 pm
UPDATE t SET t.sno = s.sno
FROM t INNER JOIN s ON s.sid=t.sid
WHERE t.sno IS NULL
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 9, 2008 at 7:47 pm
Thank you for the solution sir.
But can you please tell me why the where clause is bouncing and what is the reason?
November 10, 2008 at 1:08 am
vempralachaitanya (11/9/2008)
But can you please tell me why the where clause is bouncing and what is the reason?
Bouncing?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 10, 2008 at 6:50 am
vempralachaitanya (11/9/2008)
--Queryupdate t set t.sno=
(select s.sno from t,s where s.sid=t.sid and t.sno is null)
where t.sno is null and t.sid=s.sid
am getting the following error
--error
Msg 4104, Sevel 16, State 1, Line 1
The multi-part identifier on s.sid could not be bound
The highlighted element (s.sid) does not refer to any object used outside the subquery, hence the error. You cannot refer into a subquery, but references the other way work fine, so the following achieves what you want.update t
set t.sno=(select s.sno from s where s.sid=t.sid)
where t.sno is null
Derek
November 26, 2012 at 9:49 pm
Hi all, i m new to sql... i m facing a problem while executing this query on sql server 2005...
the multipart identifier could not be bound..
SELECT DISTINCT '(' + tblDefProducts.Product_number + ') ' + tblDefProducts.item_name AS Product_number, tblDefProducts.product_id
FROM tblDefProducts
Where 1 = 1
AND tblDefProducts.Gender In (1)
I have a table named tbllineitems having column line_item_id...i want to put a check on it that only the item against selected lineitem should be shown...plzzz help me...thanx in advance..
November 26, 2012 at 11:55 pm
Please post new questions in a new thread. Thank you.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply