0004
0004

Reputation: 1260

SQL Create A New Table off Of Query Results , in one Query

Below is my attempt to create a table from a query, having a little trouble getting the insert into statement to work, the rest of the query works great, just cannot get my return results into a new table any idea how to ?

    CREATE TABLE test (
        a varchar(255),
        b varchar(255),

    )
--I assume the above is wrong , not sure why-- 

  Insert into test (a, b)
    select (B , Cor)
    from 
    (
      --below works great---
      Select B,
             CASE
               WHEN B = 't' THEN 'test' 
               WHEN B = '-' THEN 'NULL'

               WHEN B = 'Choos' THEN 'NULL'

               WHEN B = 'Se Co' THEN 'S'

               --
               WHEN B LIKE 'Y%' THEN 'di'
               WHEN B LIKE 'T%' THEN 'Ten'
               --
               ELSE B

           END AS Cor
    FROM
      (SELECT WON AS B
       FROM ma
       UNION SELECT C
       FROM ma )
    Order By B )

Upvotes: 0

Views: 33

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271003

The parentheses are suspicious:

Insert into test (a, b)
    select (B, Cor)
-----------^

Some databases might interpret this as a single tuple (struct or record) with two fields. Some will generate an error. Basically, you want to drop the parens:

Insert into test (a, b)
    select B, Cor
    . . .

Upvotes: 1

Related Questions