sqlconcatenation

SQL print a space between concat statements


I am concatenating two columns together. I want them to display together in column with a space between the two numbers, but it keeps adding the two numbers together. One is a bigint and the other is a smallint. This will eventually be displayed in an SSRS report, but right now I'm just using SQL to query the data

(NBR +''+ ACCT_NBR) as acct,

How can I concatenate these values?


Solution

  • 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,