Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Last active February 7, 2018 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royashbrook/a26f23c6364670205b48d5f98e113456 to your computer and use it in GitHub Desktop.
Save royashbrook/a26f23c6364670205b48d5f98e113456 to your computer and use it in GitHub Desktop.
-- temp table variable
declare @tbl table (
a varchar(2)
)
insert @tbl
select 'v0'
union all select 'v1'
union all select 'v2'
select
*
from
@tbl
-- in line query
select
*
from
(
select [a] = 'v0'
union all select 'v1'
union all select 'v2'
) t
-- xml variable
declare @xml xml
set @xml = '<a>v0</a><a>v1</a><a>v2</a>'
select
[a] = t.c.value('.','varchar(2)')
from
@xml.nodes('/a ') t (c)
-- table value constructor
select
*
from
(values ('v0'), ('v1'), ('v2')) v(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment