brutusbombocloth
brutusbombocloth

Reputation: 57

Select different values into a table

Now I know how to select the outputs of a column into a table

select column1, column2 into #temptable

now, what if I just want to input the values myself into the table?

I know that

select 'a' [column1] into #temptable

works

and

select 'a' [column1] into #temptable
union
select 'b' [column1]

also works

but surely there's a less braindead way to get multiples lines of text into a row in SQL.

Upvotes: 1

Views: 61

Answers (2)

Nguyễn Văn Phong
Nguyễn Văn Phong

Reputation: 14228

Demo on db<>fiddle

You might need Desired table

select v.value
into #temptable
from (
    values ('a'), ('b'), ('c')
)v(value);

or

select 'a' as Value
into #temptable2

insert into #temptable2
values ('b'), ('c')

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1270021

Do you just want values()?

select v.*
into #temptable
from (values ('a'), ('b')) v(column1);

Upvotes: 0

Related Questions