使用来自 3 个不同 table 的字段创建 table 错误

Creating table with fields from 3 different tables Error

我正在尝试创建一个 table,它是其他 3 个 table 的组合(但由于关系需要加入 4 个)。我从这里关注 post:

Creating tables with fields from 2 different tables

当我 运行 没有 CREATE TABLE Customer_Information AS 的查询时,我没有收到任何错误并显示 table。但是当我 运行 它与 CREATE 我得到这个错误:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.

这里是查询:

CREATE TABLE Customer_Information AS (
SELECT DimServere.Servernavn, DimServere.Serverstatus,
       DimKunder.Ministerium, DimKunder.MinisteriumFuldeNavn, DimKunder.RapporteringsKunde, 
       IderaPatchAnalyzer.IP_Adresse, IderaPatchAnalyzer.Release_, IderaPatchAnalyzer.Level_, IderaPatchAnalyzer.Edition_, 
       IderaPatchAnalyzer.Build, IderaPatchAnalyzer.Updates_Available, IderaPatchAnalyzer.Supported_, IderaPatchAnalyzer.Support_Status

FROM IderaPatchAnalyzer 
        JOIN DimServere
            ON IderaPatchAnalyzer.IP_Adresse = DimServere.TcpIpAddress
        JOIN FactSystemServereKunder
            ON DimServere.Servernavn = FactSystemServereKunder.Servernavn
        JOIN DimKunder
            On FactSystemServereKunder.KundeID = DimKunder.KundeID
        WHERE DimServere.Serverstatus != 'Disposed/Retired'
        );

同样在 table IderaPatchAnalyzer 中,当我执行简单的 SELECT * FROM IderaPatchAnalyzer 时,我得到 190 行。但是当我 运行 连接 table 时,如上所示,我得到 437 行。我的目标是将信息附加到这 190 行。我不明白为什么 table 会变大。

提前致谢

我不认为,您可以这样初始化 Table。 您可以使用:

Select * Into #(tableName)From X where X = Y

但是你需要删除 Table

Drop Table #(tableName)

同样重要的是,它会说它不知道 table 但你可以毫无问题地使用它。

您的代码将如下所示:

SELECT DimServere.Servernavn, DimServere.Serverstatus,
       DimKunder.Ministerium, DimKunder.MinisteriumFuldeNavn, DimKunder.RapporteringsKunde, 
       IderaPatchAnalyzer.IP_Adresse, IderaPatchAnalyzer.Release_, IderaPatchAnalyzer.Level_, IderaPatchAnalyzer.Edition_, 
       IderaPatchAnalyzer.Build, IderaPatchAnalyzer.Updates_Available, IderaPatchAnalyzer.Supported_, IderaPatchAnalyzer.Support_Status
INTO #Customer_Information 
FROM IderaPatchAnalyzer 
        JOIN DimServere
            ON IderaPatchAnalyzer.IP_Adresse = DimServere.TcpIpAddress
        JOIN FactSystemServereKunder
            ON DimServere.Servernavn = FactSystemServereKunder.Servernavn
        JOIN DimKunder
            On FactSystemServereKunder.KundeID = DimKunder.KundeID
        WHERE DimServere.Serverstatus != 'Disposed/Retired'

        --Your Code

        DROP TABLE #Customer_Information

为你的下一个问题。您对 1 项有多个引用。在 JOIN / WHERE

中添加更多条件应该可以解决