Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL print a space between concat statements

Concatenating two columns together, Just want them to be displaying together in column with a space between the two numbers. It keeps adding the two numbers together. One is a bigint other is a smallint.Will be displayed in an SSRS report eventually but right now just using SQL to query the data

    (NBR +''+ ACCT_NBR) as acct,
like image 854
LewSim Avatar asked Oct 05 '12 18:10

LewSim


2 Answers

Though you didn't mention the database, try

MySQL

concat(NBR,' ',ACCT_NBR) as acct

SQL Server

CAST(NBR AS VARCHAR)+' '+CAST(ACCT_NBR AS VARCHAR) as acct
like image 165
codingbiz Avatar answered Sep 19 '22 07:09

codingbiz


You don't mention what flavor of SQL you're using, but depending, 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,
like image 22
Data Masseur Avatar answered Sep 21 '22 07:09

Data Masseur