Angelos Petropoulos' WebLog

Thoughts occasionally worth reading

Get a decimal that is not padded with zeros in SQL Server 2005

clock November 26, 2008 16:14 by author angelosp

In SQL when you convert anything to a decimal you have to provide the number of decimal places as part of the conversation. For example

DECLARE @NumberAsString VARCHAR(20)
SET @NumberAsString = '1038.93801'

DECLARE @NumberAsDecimal DECIMAL(28.10)
SET @NumberAsDecimal = CONVERT(DECIMAL(28,10), @NumberAsString)

If you execute SELECT @NumberAsDecimal what you get back is '1038.9380100000'. The reason why the result is padded with zeros is because the number of decimal places specified during the conversion is 10. Such a result can look very ugly in reports.

In SQL server 2005 there is no easy way to get rid of extra zeros. The fastest and simplest way I know is the following

CREATE FUNCTION GetNonPaddedDecimal
(
      @number Decimal(38,10)
)
RETURNS VARCHAR(max)
AS BEGIN
      RETURN REPLACE(RTRIM(REPLACE(REPLACE(RTRIM(REPLACE(@number, '0', ' ')), ' ', '0'), '.', ' ')), ' ', '.')  
END

Thanks to Ashar for coming up with it

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


(Interfaces && DI == Design.Good) does not always return true

clock April 30, 2008 09:38 by author angelosp

I have previously stated my reservations regarding Extensions methods, however this Eli Lopian's post still makes a good read.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


WinXP SP3 available in MSDN

clock April 24, 2008 13:24 by author angelosp

Those of you who have an MSDN subscription should be able to get WinXP SP3 by navigating to the "Top Subscriber Downloads" part of the MSDN home page (scroll at the bottom).

The link is labelled Windows XP Service Pack 3 (x86) - CD (English)

Update: It's worth noting that if for some reason you don't want Windows Update to install WinXP SP3 automatically, you can block it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


A more straightforward Microsoft Unity quickstart

clock April 22, 2008 14:54 by author angelosp

I recently downloaded and started playing with Unity, trying to see if it fits our project's needs. You can grab the installer from CodePlex, which also includes a couple of quickstarts.

Personally I found the bundled quickstarts too advanced and complicated for someone that hasn't used IoC frameworks before. In my opinion they try to demonstrate too much functionality at once. In any case, I decided to create a small project that would put Unity to use and I thought I'd share it here, as others may find it useful.

Enjoy

Simple Unity Quickstart.zip (23.13 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


ThreadPool - More threads per CPU, more memory consumed ... possible gotcha!

clock December 3, 2007 10:46 by author angelosp

So you know how the actual CLR hasn't changed since .NET 2.0? That is not entirely true (i.e. the one for Vista is a different build number), especially when you consider the .NET 3.5 release. The cut a long story short, Microsoft has taken the opportunity to include a service pack for the .NET CLR 2.0, which is a great thing as we are getting fixes for some annoying bugs.

One of the changes in SP1 of the CLR is the increase of the max number of threads per CPU that the .NET ThreadPool supports. It used to be 25 per CPU and the number has now increased to 250. Richard Blewett points out how this could be a potential gotcha as more threads means more memory consumed and ... well read the post! It's something not very likely to happen, but definitely worth knowing about. Plus, he talks about what brought this change, which is always interesting to know.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Subscribe

Syndicate
AddThis Feed Button
AddThis Social Bookmark Button

Search

Calendar

<<  January 2009  >>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Archive

Tags

Categories


Blogroll

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in