2016-09-02 7 views
0

Ich habe eine Select-Abfrage mit Joins erstellt, aber ich möchte eine Tabelle daraus erstellen. Aber SQL sagt immer ich einen Fehler haben neben dem ‚(‘, aber alle Beispiele, die ich gesehen habe eine ähnliche SyntaxErstellen einer neuen Tabelle aus verschiedenen Tabellen in Sql

create table [dbo].[PoliceDataNor] as 
(
select 
    pc.[CrimeID], 
    ct.[CrimeTypeID], 
    m.[MonthID], 
    fw.FallsWithinID, 
    ln.[LSOANameID], 
    lc.[LSOACodeID] 
from [dbo].[PoliceCrime] as pc, [dbo].[CrimeTypes] as ct, [dbo].[FallsWithins] as fw, 
[dbo].[LSAOCodes] as lc, [dbo].[LSAONames] as ln, [dbo].[Months] as m 
where 
pc.[Crime type]= ct.[Crime type] 
and 
pc.[Falls within]= fw.[Falls within] 
and 
pc.[LSOA code] = lc.[LSOA code] 
and 
pc.[LSOA name] = ln.[LSOA name] 
and 
pc.[Month] = m.[Month] 
) 
+0

gibt es keine 'create table as select ..' in sQL Server Sie sollten 'in tabellenname einfügen (c ol1, col2 ..) select ... ' –

+0

Haben Sie versucht, indem Sie ausgewählte Abfrage aus Klammern entfernen. – Navnath

+0

Sie müssen wirklich aufhören, diesen antiquierten Join-Stil zu verwenden. Der ANSI-92 Style-Join gibt es jetzt schon seit fast 30 Jahren. http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx –

Antwort

1

Dies kann getan werden, wie so mit modernen verbindet. beachten Sie, dass Einsatz in nicht-Indizes kopiert. Wenn Sie möchten abfragen müssen Sie sie prüfen, indem.

select 
    pc.[CrimeID], 
    ct.[CrimeTypeID], 
    m.[MonthID], 
    fw.FallsWithinID, 
    ln.[LSOANameID], 
    lc.[LSOACodeID] 
into [dbo].[PoliceDataNor] 
from [dbo].[PoliceCrime] as pc 
join [dbo].[CrimeTypes] as ct 
    on pc.[Crime type]= ct.[Crime type] 
join [dbo].[FallsWithins] as fw 
    on pc.[Falls within]= fw.[Falls within] 
join [dbo].[LSAOCodes] as lc 
    on pc.[LSOA code] = lc.[LSOA code] 
join [dbo].[LSAONames] as ln 
    pc.[LSOA name] = ln.[LSOA name] 
join [dbo].[Months] as m 
    pc.[Month] = m.[Month] 
2

Sie in auswählen möchten:

select 
    pc.[CrimeID], 
    ct.[CrimeTypeID], 
    m.[MonthID], 
    fw.FallsWithinID, 
    ln.[LSOANameID], 
    lc.[LSOACodeID] 
into [dbo].[PoliceDataNor] 
from [dbo].[PoliceCrime] as pc, [dbo].[CrimeTypes] as ct, [dbo].[FallsWithins] as fw, 
[dbo].[LSAOCodes] as lc, [dbo].[LSAONames] as ln, [dbo].[Months] as m 
where 
pc.[Crime type]= ct.[Crime type] 
and 
pc.[Falls within]= fw.[Falls within] 
and 
pc.[LSOA code] = lc.[LSOA code] 
and 
pc.[LSOA name] = ln.[LSOA name] 
and 
pc.[Month] = m.[Month] 
Verwandte Themen