Why am I getting a T-SQL error near the SELECT verb?

  • INSERT INTO  dbo.mixedwords (Mixed, MixLen, GoodVa)
    Values ( SELECT DISTINCT LTRIM(RTRim(mixVa) as NewTerm
                                , MixCnt 
                                , ValidVal 
                         FROM Sandbox
               )  
    Note: All objects are spelled correctly
            The SELECT query runs if highlighted and executed

  • Try without Values and the brackets (), after the INSERT INTO line just have the select statement.

  • As vulpes said, when using Select in that format, you don't use values. Your SQL should be in the format:
    INSERT INTO [DestinationTable] ([List], [of], [Column], [Names])
    SELECT [List], [of], [Column], [Names]
    FROM [SourceTable]
    {WHERE...};

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • sandyshin 42844 - Sunday, July 16, 2017 8:22 PM

    INSERT INTO  dbo.mixedwords (Mixed, MixLen, GoodVa)
    Values ( SELECT DISTINCT LTRIM(RTRim(mixVa) as NewTerm
                                , MixCnt 
                                , ValidVal 
                         FROM Sandbox
               )  
    Note: All objects are spelled correctly
            The SELECT query runs if highlighted and executed

    A missing closing parenthesis here, too: LTRIM(RTRim(mixVa)
    Not sure how it would still run if you just highlighted it and executed it.

  • INSERT INTO dbo.mixedwords (Mixed, MixLen, GoodVa)

    SELECT DISTINCT LTRIM(RTRim(mixVa))  as NewTerm

    , MixCnt

    , ValidVal

    FROM Sandbox

Viewing 5 posts - 1 through 4 (of 4 total)

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