Last post Aug 01, 2018 09:18 AM by mnmhemaj
Aug 01, 2018 08:37 AM|mnmhemaj|LINK
I have a table in which column names are month names.
I want to select data only for the column name which has current month name.
SELECT [Aug] FROM table where [colum name = current month] ( As August is the current month)
Aug 01, 2018 09:05 AM|me_ritz|LINK
Follow along the sample:
DECLARE @sql VARCHAR(2000)
CREATE TABLE TAB(
INSERT INTO TAB
SELECT 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
SELECT * FROM TAB
SET @sql = 'SELECT ' + FORMAT(GETDATE(), 'MMM', 'en-US') + ' FROM TAB'
DROP TABLE TAB
Aug 01, 2018 09:18 AM|mnmhemaj|LINK
Hi me_ritz ! Thanks for your answer. Format function is not working in my sql server edition. Instead I used Datename(MONTH, GETDATE()) .