Create empty SQL Table with customize insert a list to create a column

50 views Asked by At

I want to create #1 table In which I want insert customer ids

('123t','23x4','4g56','5k67',.....)

Customer id can be of any length.

This is the code I tried:

CREATE TABLE #1 
(
    CUSTOMER_ID VARCHAR(255)
)

INSERT INTO #1 (id) 
VALUES ('123t', '23x4', '4g56', '5k67', '5k07', '1g36', '21x4')

SELECT * FROM #1

Expected output:

Expected Output

1

There are 1 answers

7
Amit Mohanty On

You're trying to insert values into a column named id, but your table has a column named CUSTOMER_ID. Also, you mentioned that the customer IDs can be of any length, so you should use VARCHAR(MAX).

CREATE TABLE #YourTable (
    CUSTOMER_ID VARCHAR(MAX)
);

-- Insert customer IDs into the table
INSERT INTO #YourTable  (CUSTOMER_ID) VALUES 
('123t'), ('23x4'), ('4g56'), ('5k67'), 
('5k07'), ('1g36'), ('21x4');

-- Select all rows from the table
SELECT * FROM #YourTable ;