concatening 2 columns

  • i need to concatene 2 columns (firstname, lastname) to one column.

    and i am not so famliar with Tsql.

    Could somebody help?

  • Assuming firstname and lastname are strings, use the + operator

    select firstname + lastname

    or if you need readability

    select firstname + ' ' + lastname

    of coures you may also want to check for nulls - you'll know your data better than me.

    select isnull(firstname, '') + ' ' + isnull(lastname,'')

  • SELECT [FirstName] + ' ' + isnull([MiddleName], '') + ' ' +[LastName]

    FROM [AdventureWorks].[Person].[Contact]

    SELECT [au_lname] + ' ' + [au_fname] as lastname_Firstname

    FROM [pubs].[dbo].[authors]

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • yes but my problem is to concatene this 2 columns from table a to a single column to table b

  • again assuming data types are right.....

    insert into tableB (fullname)

    select firstname + ' ' + lastname from tableA

    or an UPDATE statement based on some common key between the2 tables.....

  • no problem

    Update T2

    set LastnameFirstname = T1.au_lname + ' ' + T1.au_fname

    FROM [pubs].[dbo].[authors] T1

    inner join [pubs].[dbo].[TheOtherTable] T2

    on T1.au_id = T2.theFKtoAuthors

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • woow, it s exactly what i was looking for.

    Many thanks.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply