How to solve this syntex error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jas Singh
    New Member
    • Dec 2010
    • 2

    How to solve this syntex error?

    Hello, I am a beginner to SQL. I am working on a work related request and receiving the following syntex error:

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

    I had originally wanted to change the date format to mmddyyyy. Currently it's in yyyymmdd. Can you also check if I use the convert function correctly? Thanks for the feedbacks!

    [code]
    CREATE TABLE #ID112
    (ACCT# NUMERIC)

    --="INSERT INTO #ID112 VALUES ("&A2&")"


    SELECT A.ACCT#
    , E.PANEL#
    , E.PGMTYP
    , E.DDCONT

    INTO #ID112_1
    FROM #ID112 A
    JOIN HALS_MFC.HALS.M TGLIBPN.INSOLDP L E
    ON A.ACCT# = E.ACCT#

    SELECT DISTINCT
    A.ACCT#
    ,ISNULL(B.NAME1 , C.NAME1) "NAME"
    ,ISNULL(B.ADDRS , C.ADDRS) ADDRS
    ,ISNULL(B.CTYST , C.CTYST) CTYST
    ,ISNULL(B.ZIP, C.ZIP) ZIP
    ,ISNULL(B.CLSDC D, C.CLSDCD) CLSDCD
    ,ISNULL(B.LKOTC D, C.LKOTCD) LKOTCD
    ,ISNULL(B.WARNC D, C.WARNCD) WARNCD
    ,D.CERTF# AS Cert#
    ,CertDate = convert (datetime, convert(varchar , D.CERTFD)
    ,D.MAPDTE AS MapDate
    ,A.PANEL#
    ,D.COMMUN AS Commun#
    ,D.CMSTAT AS CommunSt
    ,D.FLZONE
    ,D.DDVEND AS Vendor#
    ,A.DDCONT AS CntrctTyp
    ,A.PGMTYP AS PRGM

    INTO #ID112_FINAL
    FROM #ID112_1 A
    LEFT
    JOIN dbo.CHMSTRAA B
    ON A.ACCT# = B.ACCT#
    LEFT
    JOIN dbo.HHMSTRPL C
    ON A.ACCT# = C.ACCT#
    LEFT
    JOIN dbo.INSOLDPL D
    ON A.ACCT# = D.ACCT#
    [\code]
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    I'm not sure you're allowed to use the #-sign for your alias name and your column name.

    Good Luck!!!

    ~~ CK

    Comment

    Working...