multipart identifier could not be bound

  • 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

  • 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.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thank you for the solution sir.

    But can you please tell me why the where clause is bouncing and what is the reason?

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • vempralachaitanya (11/9/2008)


    --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

    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

  • 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..

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply