我有一张表,其中显示了分配的方式,就像我应该被
分配的方式一样这是存储过程:
select order_id, la_name, branch, la_reference_no, order_received_dt, UserName as assignby, UserName as assignto
from neworder
inner join newemployee on neworder.Assign_to = newemployee.Employeeid
where Assign_to=@userid
order by order_id
这是我的代码:
com.Parameters.AddWithValue("@flag", 1);
com.Parameters.AddWithValue("@userid", Session["User_id"].ToString());
com.CommandText = "teamandmy_pipeline"; //Stored Procedure Name
如何分配价值here there is assigned to and assigned by but it displays same name
我已经将员工ID存储在assignby中,但是应该显示姓名
答案 0 :(得分:1)
如果 AssignedTo 字段引用的名称在表 newemployee 中,则您已经拥有所有内部联接正确引用的关系。
您需要做的就是使用newemployee表中员工的姓名字段。
因此,假设此字段在newemployee表中名为 UserName ,则需要编写
SELECT no.order_id, no.la_name, no.branch, no.la_reference_no, no.order_received_dt,
no.UserName as assignby, ne.UserName as assignto
FROM neworder no INNER JOIN newemployee ne ON no.Assign_to = ne.Employeeid
WHERE no.Assign_to=@userid
ORDER BY no.order_id
请注意,要消除两个表的字段之间的歧义,每个表的名称后应有一个别名,该别名用作列名前面的前缀