Take the Whole Number (No rounding up ) T-sql




declare @val as decimal(6,3)
 
set @val = 20.575
 
 
 
select  @val
, Cast(round(@val,-1) as int) 
, parsename(cast(@val as varchar(20)),2)
,stuff(cast(@val as varchar(20)),charindex('.',cast(@val as varchar(20))),len(cast(@val as varchar(20))),'')
,floor(@val)
,cast(@val as int) myInt,
  Replace(@val,Replace(ABS(@val) % 1,'0.','.'),'')
 
,Cast (N'<root><row>' + Replace(@val, '.', '</row><row>') + '</row></root>' AS XML).value('(/root/row)[1]', 'nvarchar(50)')
 
, Stuff(@val, Charindex(0X2E, Cast(Ltrim(@val) AS VARBINARY(50)), 1), len(@val), '')  

,Cast(@val-ABS(@val) % 1 as Int)


 

http://blogs.msdn.com/b/samlester/archive/2012/10/23/tsql-solve-it-your-way-parsing-tips-and-tricks-returning-digits-after-the-decimal-point.aspx

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s