Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ho to check the Precision of a decimal field

Posted on 2013-06-24
1
Medium Priority
?
474 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
Louis01 earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

610 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