Concatenate Two Fields t-sql

5 pts.
Tags:
Concatenate
SQL Server
T-SQL
I need to concatenate two fields one varchar(50) and the other varchar(12) The result I need is to see the full 50 characters of the first field even though all 50 may not be filled. Thanks

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can CAST the first value into a CHAR field which will pad the value with spaces then put the second value on the end. Here’s an example.

<pre>declare @v1 varchar(50)
declare @v2 varchar(12)
select @v1 = ‘test’, @v2=’a’
select cast(@v1 as CHAR(50)) + @v2</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: