Solved

Ho to check the Precision of a decimal field

Posted on 2013-06-24
1
467 Views
Last Modified: 2013-06-24
Hi there

I have a column, that is set to

decimal(18,0)

I need to check the (18,0) bit of it, and if it is (18,0) run some SQL else don't run it

so

if field

share is (18,0) do something
else
don't do anything

thanks
0
Comment
Question by:mousemat24
1 Comment
 
LVL 11

Accepted Solution

by:
Louis01 earned 500 total points
ID: 39270961
To select column type and precision and scale:
select t.name as table_name, c.name as column_name, y.name as [type_name], c.precision, c.scale
  from sys.tables t
		inner join sys.columns c
	on t.[object_id] = c.[object_id]
		inner join sys.types y
	on c.system_type_id = y.system_type_id
 where t.name = 'your_table_name_here'
   and c.name = 'your_column_name_here'
--   and y.name = 'decimal'
--   and c.precision = 18
--   and c.scale = 0

Open in new window



To use in IF
IF ((select isnull(count(*), 0)
	  from sys.tables t
			inner join sys.columns c
		on t.[object_id] = c.[object_id]
			inner join sys.types y
		on c.system_type_id = y.system_type_id
	 where t.name = 'your_table_name_here'
	   and c.name = 'your_column_name_here'
	   and y.name = 'decimal'
	   and c.precision = 18
	   and c.scale = 0) = 0)
BEGIN
	Print 'Do something'
END
ELSE
BEGIN
	Print 'Do something else'
END

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now