Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting or getting rid of decimal places 1

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
969
0
16
GB
HI

I have 2 fields both numeric which I want to join together. I have the below line of code

CAST(dbo.Product.Thickness AS varchar) + ' x ' + CAST(dbo.Product.Width AS varchar),

This give me the result of

38.00000000 x 100.00000000

I want it to it is just

38 x 100

How can I get rid of the .0000000 . I have tried a few things I have googled but cannot get it working.

Any ideas please. Many thsnks
 
One way would be to use Charindex (some might know it as instring). Something like this (not tested)
left(CAST(dbo.Product.Thickness AS varchar), Charindex('.',CAST(dbo.Product.Thickness AS varchar))-1)+ ' x ' + left(CAST(dbo.Product.Width AS varchar), Charindex('.',CAST(dbo.Product.Width AS varchar))-1)
 
How about:
[tt]
CAST(dbo.Product.Thickness As [blue]Int[/blue]) + ' x ' + CAST(dbo.Product.Width As [blue]Int[/blue])
[/tt]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek : You would need a second cast so that you can to the concatenation;

Cast( CAST(dbo.Product.Thickness As Int) as varchar) + 'x' + cast(CAST(dbo.Product.Width As Int) as varchar)
 
Thanks all it is now working. kray4660 did the trick

Many thanks
 
kray4660, you are right.
I've just tried:[tt]
CAST(38.00000000 As Int) [/tt] and that gave me 38, but the over all outcome should be CAST as varchar

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top