Click here to Skip to main content
13,346,966 members (72,647 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi All
i have this Query Below
string updateReq = "UPDATE Student SET Student.ID_Request = Request.ID_Request FROM Request where Student.St_Code=Request.St_Code   INNER JOIN  Request ON Student.ID_Request = Request.ID_Request";


but when i excute this i get this error :
The objects "Request" and "Request" in the FROM clause have the same exposed names. Use correlation names to distinguish them.


how can i solve this ?

What I have tried:

i tried to select the records in the temp table but it doesn't work or maybe i do it wrong

string select = "SELECT * INTO #TempTable FROM Student s where ID_Request IS NULL";

string updateReq = "UPDATE TempTable SET s.ID_Request = Request.ID_Request FROM Request where Student.St_Code=Request.St_Code   INNER JOIN  Request ON Student.ID_Request = Request.ID_Request";


when i excute these string i get the same error
Posted 3-Nov-17 10:57am
Updated 3-Nov-17 18:47pm
v2
Comments
santosh kumar pithani 3-Nov-17 23:56pm
   
Don't post like this question, "filter(where) condition always comes after join.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

UPDATE Student SET Student.ID_Request = R1.ID_Request
     FROM Request R1  
          INNER JOIN Request R2 
             ON (Student.ID_Request = R2.ID_Request) 
          INNER JOIN  Student 
             ON (Student.St_Code=R2.St_Code) 
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You have to distinguish between the two instances of the same table. I will try to help but I'm doing this on a phone...
string updateReq = "UPDATE Student SET Student.ID_Request = R1.ID_Request FROM Request R1 where Student.St_Code=Request.St_Code INNER JOIN Request R2 ON Student.ID_Request = R2.ID_Request";
I can't test this but note that I've given the tables an alias each.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 3 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100