all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

Concatenation of a number to a decimal column


Concatenation of a number to a decimal column Steve
2/8/2005 9:02:39 PM
sql server programming:
Hello

Is it possible to concatenate a number to a decimal field? I want to
concatenate the two digit system month to a decimal field (within a query)
but am struggling.

Thank you.

Re: Concatenation of a number to a decimal column Aaron Weiker
2/8/2005 10:21:21 PM
[quoted text, click to view]

SELECT CONVERT(DECIMAL(9,2), MONTH(GETDATE()))

--
Aaron Weiker
http://aaronweiker.com/
Re: Concatenation of a number to a decimal column Steve Kass
2/8/2005 11:49:32 PM
You can convert both values to strings to do the concatenation:

select
cast(decCol as varchar(20)) + right(month(getdate())+100,2)
from ...
-- the right() business is to get a leading zero.

If you know the scale of your decimal value, say it's decimal(8,2),
you could also do this:

select
cast(decCol + month(getdate())*0.0001 as decimal(10,4))
from ...

The cast is not needed here, but the rules for typing the
results of decimal arithmetic are not always clear, so I'm
playing it safe.

Steve Kass
Drew University

[quoted text, click to view]
AddThis Social Bookmark Button