[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Concatenating a numeric field with a varchar field

Posted on 2004-11-26
4
Medium Priority
?
863 Views
Last Modified: 2012-05-05
I am trying to concatenate a numeric field with a varchar field in a view.  If I use the & sign or the + sign I get an error.  Is there a way to concatenate them or change the number field to a text field?

Thanks,

Andy
0
Comment
Question by:ajdajd
  • 3
4 Comments
 
LVL 13

Expert Comment

by:MikeWalsh
ID: 12684316
select convert(varchar(50), 1) + 'hi'
0
 
LVL 13

Expert Comment

by:MikeWalsh
ID: 12684318
so SELECT convert(varchar(50), YourIntColumn) + YourVarcharColumn will give you what you are looking for. It should anyway.
0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 12685029
if the numeric is an integer then varchar(10) is sufficient, which will keep your selected column size down...

   generally you need

SELECT coalesce(convert(varchar(10), YourIntColumn),'') + YourVarcharColumn

if the numeric column could be null ...
0
 
LVL 13

Expert Comment

by:MikeWalsh
ID: 12685883
Good point with the coalesce, lowfat.. My mind nulled out the possibility of null.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question