3

I want to create a table variable or temporary table, using data from another table but with an extra column.

I know I could use SELECT INTO as follows

SELECT *
INTO #TempTable
FROM Existing_Table
WHERE Section = 2

and then use

ALTER TABLE #TempTable ADD New_Column

And finally

DROP #TempTable

I will then be looping through each row with a dynamically called stored procedure to place values in the new column. Its not a big table.

Is that the best way? My understanding is that I cannot use the above with a table variable.

Thanks

Chris.

0

1 Answer 1

4

Its simpler

SELECT *, cast('hbkkj' as nvarchar(100)) as New_Column
INTO #TempTable
FROM Existing_Table
WHERE Section = 2
Sign up to request clarification or add additional context in comments.

Comments

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.