Check for Decimals in a Value

Posted: July 14, 2011 in SQL Server 2005

TO check if a value has decimals, run the following script:

-- Declare variables
DECLARE @ln_value NUMERIC(18,4);

-- Initialise variables
SET @ln_value = 18.1234;

-- Check for decimals
IF FLOOR(@ln_value) <> CEILING(@ln_value)
BEGIN
   SELECT 'Decimals of ' + CAST((@ln_value - FLOOR(@ln_value)) AS VARCHAR(10));
END;
ELSE
BEGIN
   SELECT 'No decimals...';
END;
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