1

I have table with a integer column and the data as below:

4,89, 8, 1

How can I insert above integers in to a column.

1
  • 1
    What have you tried so far? Where are you stuck? Commented Feb 2, 2020 at 21:07

3 Answers 3

2

This can be achieved with a Table Value Constructor

Example:

Select *
From (Values (1),(2),(3),(4)) tabA (ColA)
Sign up to request clarification or add additional context in comments.

Comments

1

Automatically:

DECLARE @DataSource TABLE
(
    [ColumnValue] INT
);

DECLARE @Input VARCHAR(MAX) = '4,89, 8, 1';

DECLARE @InputXML XML = CAST(N'<r><![CDATA[' + REPLACE(@Input, ',', ']]></r><r><![CDATA[') + ']]></r>' AS XML);

INSERT INTO @DataSource
SELECT RTRIM(LTRIM(Tbl.Col.value('.', 'INT'))) AS Code 
FROM @InputXML.nodes('//r') Tbl(Col)

Comments

-2
Select *
From (Values (1),(2),(3),(4)) table (ColumnA)

1 Comment

Please add a short description into your answer to make it more useful

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.