Concatenating a numeric field with a varchar field

Posted on 2004-11-26
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?


Question by:ajdajd
    LVL 13

    Expert Comment

    select convert(varchar(50), 1) + 'hi'
    LVL 13

    Expert Comment

    so SELECT convert(varchar(50), YourIntColumn) + YourVarcharColumn will give you what you are looking for. It should anyway.
    LVL 50

    Accepted Solution

    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 ...
    LVL 13

    Expert Comment

    Good point with the coalesce, lowfat.. My mind nulled out the possibility of null.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now