Concatenate SQL Server

0

I have the following query:

SELECT UPPER(admatribuido) AS [admAtribuido], Count(admatribuido) AS [quantidade_admAtribuido] FROM ##tmp WHERE Month(dataabertura) = Month(Getdate()) AND Year(dataabertura) = Year(Getdate()) AND admAtribuido <> 'null' GROUP BY admatribuido

Which brings me the following return:

Iwouldliketoconcatenateadash"-" and the assigned_qualum in the assignedAutomation, for example:

admAtribuido              |   quantidade_admAtribuido               
ANA PAULA SOARES - 100    |   100 
    
asked by anonymous 18.01.2018 / 16:40

2 answers

2
SELECT concat( UPPER(admatribuido), ' - ',cast([quantidade_admAtribuido] as varchar(100)))        AS [admAtribuido], 
   Count(admatribuido) AS [quantidade_admAtribuido]

Use the concat function as in the example above

    
18.01.2018 / 16:55
2

Uses the standard MSSQL concatenation operator, the "+":

1 - With the 2 fields:

SELECT (UPPER(admatribuido) + ' - ' + Count(admatribuido)) AS [admAtribuido], 
       Count(admatribuido) AS [quantidade_admAtribuido] 
FROM   ##tmp 
WHERE  Month(dataabertura) = Month(Getdate()) 
       AND Year(dataabertura) = Year(Getdate())
AND admAtribuido <> 'null'
GROUP  BY admatribuido

2 - With 1 field:

SELECT (UPPER(admatribuido) + ' - ' + Count(admatribuido)) AS [admAtribuido]
FROM   ##tmp 
WHERE  Month(dataabertura) = Month(Getdate()) 
       AND Year(dataabertura) = Year(Getdate())
AND admAtribuido <> 'null'
GROUP  BY admatribuido

This solution applies to these applications below:

SQL Server (as of 2008) Microsoft Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse

    
18.01.2018 / 17:01