SQL prints space between concat expressions

Join two columns together. Just try to make them appear together in a column with a space between two numbers. He continues to add two numbers together. One of them is bigint, small is small. Will appear in the SSRS report in the end, but right now, using SQL to query the data

(NBR +''+ ACCT_NBR) as acct, 
+4
source share
6 answers

You do not indicate what taste of SQL you use, but depending on this, you may need to convert the values ​​to strings first. For SQLSever ...

 (Cast(NBR as varchar(20)) + ' ' + Cast(ACCT_NBR as varchar(20))) as acct, 
+4
source

Although you did not mention the database, try

MySQL

 concat(NBR,' ',ACCT_NBR) as acct 

SQL Server

 CAST(NBR AS VARCHAR)+' '+CAST(ACCT_NBR AS VARCHAR) as acct 
+12
source

If it is an Oracle database, try

 NBR || ' ' || ACCT_NBR as acct 
0
source
 Stuff(Coalesce(', ' + [Address1], '') + Coalesce(', ' + [Address2], '') + Coalesce(', ' + [City], '') + Coalesce(', ' + [State], '') + Coalesce(', ' + [Country], '') +Coalesce('-' + [Zip], ''), 1, 1, '') AS [Address] FROM Customers 
0
source

I know that this mail has already been answered and is correct. But I would like to post the answer below, because with SQL Server 2017 onwards it is too easy, and some may find this useful in the future.

 CONCAT_WS(CHAR(10),Cast(NBR as varchar(20)) ,Cast(ACCT_NBR as varchar(20))) as acct 

CHAR (10) can be a space in SQL SERVER. You can replace CHAR (10) with whatever separator you like. For instance,

 CONCAT_WS(',',Cast(NBR as varchar(20)) ,Cast(ACCT_NBR as varchar(20))) as acct 

the above query will add the separator ',' between each concatenated string.

0
source

In Teradata SQL you can use below. The last 3 days will be pulling.

 WHERE create_ts BETWEEN (DATE -3 || ' ' || '00:00:00') AND (DATE -1 || ' ' || '23:59:59') 
-3
source

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


All Articles