Dylan Czenski
Dylan Czenski

Reputation: 1365

Display multiple single values in a single column

I have several (about 4) single values returned by datepart() such as:

DATEPART(MONTH, DATEADD(MONTH, +3, GETDATE()))
DATEPART(MONTH, DATEADD(MONTH, +5, GETDATE()))

And I want to display them in a column, let's name it col1. I am thinking about doing something like this:

with col1 as (
    -- put these values in a column
)
select * from col1

How do I achieve this? Any approach is ok.

Upvotes: 1

Views: 36

Answers (2)

user2316154
user2316154

Reputation: 334

I'm not quite sure I understand the question, but:

If you're just looking to append those values into one column you can just do it something like this:

SELECT 
  DATEPART(MONTH, DATEADD(MONTH, +3, GETDATE())) + ' - ' + DATEPART(MONTH, DATEADD(MONTH, +5, GETDATE()))
AS Col1

Make sure, though, that you're not really looking for functionality that DATEADD or FORMAT can do for you.

EDIT: Or, if you are looking to list the values as separate rows in a column then yes, gofr1 has the answer for you!

Upvotes: 0

gofr1
gofr1

Reputation: 15977

SELECT DATEPART(MONTH, DATEADD(MONTH, +3, GETDATE())) as col1
UNION ALL
SELECT DATEPART(MONTH, DATEADD(MONTH, +5, GETDATE()))

Upvotes: 1

Related Questions