TBSupport
asked on
T-SQL: Concatenating two numbers--not adding them
Hello:
Below is my T-SQL script where I'm trying to take the last four digits of a Social Security Number and append with the year of that employees birthdate.
select right(UPR00100.SOCSCNUM, 10)+datepart(yy, UPR00100.BRTHDATE) from UPR00100
Instead, this script is mathematically adding the two numbers together.
What do I need to do to get the script to simply show me the two numbers combined and not added?
Thanks!
TBSupport
Below is my T-SQL script where I'm trying to take the last four digits of a Social Security Number and append with the year of that employees birthdate.
select right(UPR00100.SOCSCNUM, 10)+datepart(yy, UPR00100.BRTHDATE) from UPR00100
Instead, this script is mathematically adding the two numbers together.
What do I need to do to get the script to simply show me the two numbers combined and not added?
Thanks!
TBSupport
ASKER
Thanks, Dulton!
I'm getting the following error, upon running this:
Incorrect syntax near the keyword 'AS'.
TBSupport
I'm getting the following error, upon running this:
Incorrect syntax near the keyword 'AS'.
TBSupport
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
x
>> I'm trying to take the last four digits of a Social Security Number and append with the year of that employees birthdate. <<
SELECT right(UPR00100.SOCSCNUM, 4) + convert(char(4), UPR00100.BRTHDATE, 112)
from UPR00100
SELECT right(UPR00100.SOCSCNUM, 4) + convert(char(4), UPR00100.BRTHDATE, 112)
from UPR00100
ASKER
Dulton is close. But, it is not concatenating the two fields. It has approximately four spaces between them.
Here is the revised and correct solution:
select rtrim(Cast(right(upr00100. socscnum,1 0) AS VARCHAR(10)))
+ Cast(Year(upr00100.brthdat e) AS VARCHAR(4)) as test from UPR00100
Thanks, Dulton!
TBSupport
Here is the revised and correct solution:
select rtrim(Cast(right(upr00100.
+ Cast(Year(upr00100.brthdat
Thanks, Dulton!
TBSupport
Open in new window