Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 3-Nov-17 17:47pm
v2
Comments
Santosh kumar Pithani 3-Nov-17 23:56pm    
Don't post like this question, "filter(where) condition always comes after join.

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) 
 
Share this answer
 
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...
SQL
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.
 
Share this answer
 

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