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.
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;
See SQL Fiddle with Demo
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