Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
krabople
Starting Member
17 Posts |
Posted - 2008-05-23 : 06:39:18
|
| Hi, I have the following code in a query:SELECT [Issue date],DATEDIFF("dd",[Issue date],[Start date])/365 AS runningdaysFROM Database1..[Insurance Policies Working DB]WHERE [Policy Number] LIKE '%1368529%'The part 'DATEDIFF("dd",[Issue date],[Start date])' comes out as 364 if calculated on its own. However, then when it is divided by 365 it comes out as 0. How do I get it to show as a decimal instead of just rounding it down automatically? (Hope I've made sense)Thanks in advance |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-23 : 06:43:55
|
/ 365.0Integer division. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
krabople
Starting Member
17 Posts |
Posted - 2008-05-23 : 07:02:40
|
| Perfect, thanks! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-23 : 07:43:00
|
quote: Originally posted by krabople Hi, I have the following code in a query:SELECT [Issue date],DATEDIFF("dd",[Issue date],[Start date])/365 AS runningdaysFROM Database1..[Insurance Policies Working DB]WHERE [Policy Number] LIKE '%1368529%'The part 'DATEDIFF("dd",[Issue date],[Start date])' comes out as 364 if calculated on its own. However, then when it is divided by 365 it comes out as 0. How do I get it to show as a decimal instead of just rounding it down automatically? (Hope I've made sense)Thanks in advance
The reason for this is because of implicit conversion. See this:-http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx |
 |
|
|
|
|
|
|
|