As we can write in SQL to return single static value
select "Jan" as StartMonth
In the similar way, SQL should allow to write to return multiple values in same column
select {"Jan", "Feb", "Mar"} as Qtr1, {"Apr", "May", "Jun"} as Qtr2
When we need data as table to perform join and data is unknown at Sp level, i.e., it is coming from parameter, it appears unnecessary tasks to create a temp table and insert split values in the temp table. Correct me if such feature exist in MS SQL server. Or better way to have it other than pivot and temp table.
Selecting Static Values Static values can be inserted into a resultset returned from a SELECT query as another column. Simply use the static value as a column to select, and the query will return a column where the name of the column is the static value, and every row in that column will return that same static value.
To select multiple values, you can use where clause with OR and IN operator.
Note – Use of IN for matching multiple values i.e. TOYOTA and HONDA in the same column i.e. COMPANY. Syntax: SELECT * FROM TABLE_NAME WHERE COLUMN_NAME IN (MATCHING_VALUE1,MATCHING_VALUE2);
Will this give you what you want?
SELECT 'Jan' AS Qtr1, 'Apr' AS Qtr2
UNION ALL SELECT 'Feb' AS Qtr1, 'May' AS Qtr2
UNION ALL SELECT 'Mar' AS Qtr1, 'Jun' AS Qtr2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With