Skip to content
Advertisement

Need to combine two columns in a table [closed]

I need to combine two column in a table using alias name

select 
    firstname as fn,
    lastname as ln,
    userid,
    fn + '' + ln as fullname 
from 
    users 

Error is

Invalid column name ‘fn’.
Invalid column name ‘Ln’.

Advertisement

Answer

IN Sql server 2010,2012 use CONCAT(firstname , ‘ , ‘ , lastname )

2008 and lower version just use as

select firstname + ” + lastname as fullname from users.

if you alias name then

select fn+ ‘ ‘ + ln as fullname from ( select firstname as fn, lastname as ln, userid from users )

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement