Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate 2 numbers in SQL Server

I'm in need of a function to concatenate 2 numbers in SQL Server

eg

getuserid(3,333) = 3333
getuserid(8,5) = 8005
getuserid(2,11) = 2011

It should return the result based on the length of second parameter (like 3rd example)

I tried converting it to string and using case statements I concatenated it. But, I feel that,this can be done mathematically in a more effective manner. Can anyone please suggest a way.?

By the by, the output returned should be a numeric type.!

like image 534
Pavan Kumar Avatar asked Jun 13 '26 01:06

Pavan Kumar


1 Answers

Looks like this will do it:

select num1 * 1000 + num2

Why do you need a function for this simple math?

like image 146
Bohemian Avatar answered Jun 17 '26 20:06

Bohemian