Question

  Asked: Jun 25 2008   3:41 PM GMT
  Asked by: Jp5282


Concatenate Two Fields t-sql


SQL Server, T-SQL, Concatenate

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

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



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.

declare @v1 varchar(50)
declare @v2 varchar(12)
select @v1 = 'test', @v2='a'
select cast(@v1 as CHAR(50)) + @v2
  • AddThis Social Bookmark Button

Browse more Questions and Answers on SQL Server and Development.

Looking for relevant SQL Server Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register