Msg 156, Level 15, State 1, Line 2, Incorrect syntax near the keyword 'AS'.

  • I'm trying to create a new table while referencing other columns from another table in another database. Could please tell me what I'm doing wrong I'm SQL.

    CREATE TABLE HCMBMaps

    AS (SELECT mecase.CASETYPE AS "Case#", mecase.mannerappears AS "Appearstobe", mecase.injurystreet + mecase.injurycity + mecase.injurycounty + mecase.injuryzip AS "Placeofinjury", mecase.deathstreet + mecase.deathcity + mecase.deathcnty + mecase.deathzip AS "Placeofdeath", mecase.cause_a AS "Primarycauseofdeath", mecase.manner AS "Mannerofdeath"

    FROM dbo.mecase WHERE 1 = 0);

  • SQL Server doesn't use the syntax CREATE TABLE...AS... Instead, it uses SELECT...INTO...

    This should be what you're looking for.

    SELECT mecase.CASETYPE AS [Case#],

    mecase.mannerappears AS [Appearstobe],

    mecase.injurystreet + mecase.injurycity + mecase.injurycounty + mecase.injuryzip AS [Placeofinjury],

    mecase.deathstreet + mecase.deathcity + mecase.deathcnty + mecase.deathzip AS [Placeofdeath],

    mecase.cause_a AS [Primarycauseofdeath],

    mecase.manner AS [Mannerofdeath]

    INTO HCMBMaps

    FROM dbo.mecase

    WHERE 1 = 0;

    This is part of why there's no real code portability from one RDBMS to another.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Thanks Luis that worked perfectly.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply