其中main表和move表通过equno关联,move表和dept表通过部门编号No实现,
说明:beforeno是移动前的部门编号,afterno是移动后的部门编号.
现要求实现:
按部门编号No可搜索该部门所有equno的信息.显示字段包括以上列举的,见下:
equno,equname,移动前部门名称,移动后部门名称(根据beforeno,afterno得到)???
5 个解决方案
#1
SELECT A.equno B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
#2
存储过程:
CREATE PROCEDURE USP_Name
@equno nvarchar(20) --要输入的部门
AS
SELECT A.equno,B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
WHERE A.equno=@equno
GO
CREATE PROCEDURE USP_Name
@equno nvarchar(20) --要输入的部门
AS
SELECT A.equno,B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
WHERE A.equno=@equno
GO
#3
多谢,
可能是我没有说清楚.
要显示的数据:
equno,equname,移动前部门名称,移动后部门名称(根据beforeno,afterno得到)???
其中移动前部门名称就是beforeno在部门表dept中对应的name值.
在main和move表中存放的是部门编号,但用户界面上要求显示在dept中真正的部门名称值.
可能是我没有说清楚.
要显示的数据:
equno,equname,移动前部门名称,移动后部门名称(根据beforeno,afterno得到)???
其中移动前部门名称就是beforeno在部门表dept中对应的name值.
在main和move表中存放的是部门编号,但用户界面上要求显示在dept中真正的部门名称值.
#4
多谢,问题解决.
马上就贴.
马上就贴.
#5
帮顶
#1
SELECT A.equno B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
#2
存储过程:
CREATE PROCEDURE USP_Name
@equno nvarchar(20) --要输入的部门
AS
SELECT A.equno,B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
WHERE A.equno=@equno
GO
CREATE PROCEDURE USP_Name
@equno nvarchar(20) --要输入的部门
AS
SELECT A.equno,B.equname,C1.[name] AS [移动前部门名称],C2.[name] AS [移动后部门名称]
FROM move AS A
INNER JOIN main AS B ON B.equno=A.equno
INNER JOIN [move] AS C1 ON C1.[No]=A.beforeno
INNER JOIN [move] AS C2 ON C2.[No]=A.afterno
WHERE A.equno=@equno
GO
#3
多谢,
可能是我没有说清楚.
要显示的数据:
equno,equname,移动前部门名称,移动后部门名称(根据beforeno,afterno得到)???
其中移动前部门名称就是beforeno在部门表dept中对应的name值.
在main和move表中存放的是部门编号,但用户界面上要求显示在dept中真正的部门名称值.
可能是我没有说清楚.
要显示的数据:
equno,equname,移动前部门名称,移动后部门名称(根据beforeno,afterno得到)???
其中移动前部门名称就是beforeno在部门表dept中对应的name值.
在main和move表中存放的是部门编号,但用户界面上要求显示在dept中真正的部门名称值.
#4
多谢,问题解决.
马上就贴.
马上就贴.
#5
帮顶