团队表
TeamID (PK)
TeamName
CoachID (FK)
固定表格
FixtureID (PK)
Venue
Team1 (FK) to TeamTable
Team2 (FK) to TeamTable
FixtureDate
我已经创建了一个存储过程
CREATE PROCEDURE [dbo].[PR_Fixture_SelectAll]
AS
SELECT
[dbo].[Fixture].[FixtureID],
[dbo].[Fixture].[Venue],
[dbo].[Fixture].[Team1],
[dbo].[Fixture].[Team2],
[dbo].[Fixture].[FixtureDate],
[dbo].[Team].[TeamName]
FROM
[dbo].[Fixture]
INNER JOIN
[dbo].[Team] ON [dbo].[Team].[TeamID] = [dbo].[Fixture].[Team1]
INNER JOIN
[dbo].[Team] t ON[dbo].[Team].[TeamID] = [dbo].[Fixture].[Team2]
存储过程在执行时仅显示列名,而不显示插入的数据
答案 0 :(得分:0)
这可能对您有帮助
DECLARE @Team TABLE
(
TeamID INT ,
TeamName VARCHAR(50),
CoachID INT
)
DECLARE @Fixture Table
(
FixtureID INT,
Venue VARCHAR(50),
Team1 INT ,
Team2 INT,
FixtureDate DATE
)
INSERT INTO @Team(TeamID,TeamName,CoachID) VALUES(1,'A',1)
INSERT INTO @Team(TeamID,TeamName,CoachID) VALUES(2,'B',2)
INSERT INTO @Team(TeamID,TeamName,CoachID) VALUES(3,'C',3)
INSERT INTO @Team(TeamID,TeamName,CoachID) VALUES(4,'D',4)
INSERT INTO @Fixture(FixtureID,Venue,Team1,Team2,FixtureDate) VALUES(1,'X',1,3,GETDATE())
INSERT INTO @Fixture(FixtureID,Venue,Team1,Team2,FixtureDate) VALUES(2,'Y',2,4,GETDATE())
SELECT
f.FixtureID,
f.Venue,
t1.TeamName Team1,
t2.TeamName Team2,
f.FixtureDate
FROM @Fixture f
Inner Join @Team t1 ON f.Team1 = t1.TeamID
Inner Join @Team t2 ON f.Team2 = t2.TeamID