Table: I have a database table table_1 in SQL Server 2012 with data as:
CREATE TABLE table_1 ([ID] BIT, [Name] VARCHAR(10))
INSERT INTO table_1 ([ID],[Name]) VALUES (1,'A')
INSERT INTO table_1 ([ID],[Name]) VALUES (0,'B')
INSERT INTO table_1 ([ID],[Name]) VALUES (0,'C')
What I want is a single row with two columns in the result. Like:
col_1 col_2
2 B, C have zero value
So I want to know how many entries in column [ID] are 0 and then display count of those as col_1 in result. Then col_2 should have all the (concatenated) strings from column [name] when column [ID] had 0. THis later part to get concatenated strings from column [name] is what I am unable to get.
It must be very simple but I can't get it done beyond this SQL:
SELECT COUNT(*) AS col_1 FROM table_1 WHERE ID = 0;
How can I add second column col_2 that'll have concatenated strings from col_2? If the count(*) is zero then col_2 can be empty. (Would be great if I can add NA)
I tried to use solutions from these threads url1 and url2 but couldn't customize it to get count(*) as zero when ID column doesn't have any 0.