Unix Technical Forum

Re: Limiting precision when using a formula for field

This is a discussion on Re: Limiting precision when using a formula for field within the SQL Server forums, part of the Microsoft SQL Server category; --> You can cast to the appropriate decimal scale: Use this as your formula: cast( (datediff(day,[Hire Date], (convert(datetime,convert(varchar,getdate(),1),1)) ) / ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:00 PM
Steve Kass
 
Posts: n/a
Default Re: Limiting precision when using a formula for field

You can cast to the appropriate decimal scale:

Use this as your formula:

cast(

(datediff(day,[Hire Date],
(convert(datetime,convert(varchar,getdate(),1),1)) ) / 365.0)

as decimal(6,2))

(Also, using 365.24 will be a bit closer to correct
if this is intended to calculate a number of years.)

Steve Kass
Drew University




papernate wrote:

>I'm creating a field to keep track of how long someone has worked here.
>I only want to have a precision of 2, and currently have this formula
>entered in for the field:
>
>(datediff(day,[Hire Date],
>(convert(datetime,convert(varchar,getdate(),1),1) )) / 365.0)
>
>
>
>The "precision" property is greyed out on me, and I'm not being allowed
>to select the data type I want. Any ideas?
>
>--
>Posted via http://dbforums.com
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:15 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com