Add text to each sql select query string

I have a request like this

SELECT COUNT(ID) 'Records Affected', TYPE FROM MASTER GROUP BY TYPE 

Way out for that

 Records Affected TYPE ---------------- ---- 4 F1 3 F2 5 F3 

Now I would like to modify the query so that the result is 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 to add default text to each row of the result set instead of adding in the interface. I would like to simplify the task of just showing the records in the DataGrid as Summary.

+6
source share
5 answers

You can easily concatenate a string using the following. You will use + to combine the row with the type and count column. Note that count must be converted to varchar for this:

 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

+10
source

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 
+1
source
 SELECT "The number of records affected for " + TYPE + " is : " + COUNT(ID) AS [Records Affected] FROM Master GROUP BY TYPE 
+1
source

Try the following:

 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 
0
source

Use this query:

 UPDATE bookmark_linx SET link_url=(SELECT CONCAT(link_url, '?raw=true')) WHERE link_url LIKE '%dropbox%' 
0
source

Source: https://habr.com/ru/post/946697/


All Articles