Reputation: 1150
I have a query like this
SELECT COUNT(ID) 'Records Affected', TYPE FROM MASTER
GROUP BY TYPE
The output for this is
Records Affected TYPE
---------------- ----
4 F1
3 F2
5 F3
Now I would like to change the query so that the output will be as follows
Records Affected
----------------
The number of records affected for F1 is : 4
The number of records affected for F2 is : 3
The number of records affected for F3 is : 5
"The number of records affected for " + TYPE + " is : " + COUNT.
How can I add the default text to each row of the result set instead of appending in the front end. I would like to simplify my task of just showing the records in the DataGrid as Summary.
Upvotes: 9
Views: 100479
Reputation: 11
Use this query:
UPDATE bookmark_linx SET link_url=(SELECT CONCAT(link_url, '?raw=true')) WHERE link_url LIKE '%dropbox%'
Upvotes: 1
Reputation: 7876
SELECT "The number of records affected for " + TYPE + " is : " + COUNT(ID) AS [Records Affected]
FROM Master
GROUP BY TYPE
Upvotes: 1
Reputation: 3493
Just put the text in your query:
SELECT 'The number of records affected for ' + TYPE + ' is : ' + CAST(COUNT(ID) as VARCHAR(20)) AS 'Records Affected' FROM MASTER
GROUP BY TYPE
Upvotes: 2
Reputation: 247650
You can easily concatenate the string using the following. You will use the +
to concatenate the string to the type
column and the count
. Note, the count
needs to be converted to a varchar
for this to work:
SELECT
'The number of records affected for '+ type +
' is : '+ cast(COUNT(ID) as varchar(50)) as'Records Affected'
FROM yt
GROUP BY TYPE;
Upvotes: 14
Reputation: 3752
Try this:
SELECT 'The number of records affected for ' + TYPE + ' is : ' +
STR(X.[Records Affected]) AS [Records Affected]
FROM (SELECT COUNT(ID) 'Records Affected', TYPE FROM MASTER GROUP BY TYPE) X
Upvotes: 0