| Author |
Topic |
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 05:08:35
|
can anyone help with the following codeI am writing with limited access to a database originally i used a predefined function as follows USE [FMData]GO/****** Object: UserDefinedFunction [dbo].[GetFMDate] Script Date: 07/21/2008 09:51:49 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[GetFMDate] (@Input_Date as int) RETURNS DateTimeBEGINDECLARE @Output as DateTimeIF @Input_Date <> 0 AND @Input_Date>700000 BEGIN SET @Output = CONVERT(DATETIME, @Input_Date - 693596) ENDELSE BEGIN SET @Output = NULL ENDRETURN @OutputENDhowever i now dont have access to this function and have been told to use CONVERT(DATETIME, dbo.PROGRESS.Scheduled_to_Start - 693596) AS Datehowever this is comming up with the dreaded arithmetic overflow errorthe original data looks like this733240can you help |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 05:12:37
|
what date does 733240 represent ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-21 : 05:18:08
|
| What does the function do?MadhivananFailing to plan is Planning to fail |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 05:23:48
|
| I beleive when it was working it would look like this17/07/2008 09:17RegardsDamian |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-21 : 05:32:18
|
| In the function, change the following SET @Output = CONVERT(DATETIME, @Input_Date - 693596)toSET @Output = DATEADD(day, @Input_Date - 693596,0)MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 06:16:27
|
| I wish i could post the values you want but without access to that function i cannot get anything to work so im stuck right royallythe only way i can get you something is to interpret the proprietry software.i get this733245 18/07/08733247 21/07/08733251 22/07/08I beleive that these will all be expressed with a 00:00 time on the end due to a fault in the software not making all times to 0RegardsDamian |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-21 : 06:34:51
|
Seems odd.The first two records have an absolute difference of 2, but the dates are 3 days off.And then record 2 and 3 has an absolute difference of 4, but days are only 1 day off.Are you REALLY REALLY sure the integer values and the dates correlate? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 06:36:00
|
| PesoBear with me i will try to get you more accurate valuesD |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 06:49:42
|
| Try these733245 22/07/2008733226 03/07/2008733247 24/07/2008733289 04/09/2008733273 19/08/2008733276 22/08/2008I have pulled these from the sales ledger where one order number is delivering one individual part at one delivery dateD |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-21 : 06:52:24
|
Is there another column that has time part stored? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 06:56:43
|
| sorry my fault733245 22/07/2008 00:00733226 03/07/2008 00:00733247 24/07/2008 00:00733289 04/09/2008 00:00733273 19/08/2008 00:00733276 22/08/2008 00:00when i interpret the software it doesnt display timed |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-21 : 06:57:58
|
TrySELECT DATEADD(DAY, dbo.PROGRESS.Scheduled_to_Start - 693596, '19000101') AS Date E 12°55'05.25"N 56°04'39.16" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-21 : 07:02:12
|
[code]DECLARE @Sample TABLE (v INT, d DATETIME)SET DATEFORMAT DMYINSERT @SampleSELECT 733226, '03/07/2008' UNION ALLSELECT 733245, '22/07/2008' UNION ALLSELECT 733247, '24/07/2008' UNION ALLSELECT 733273, '19/08/2008' UNION ALLSELECT 733276, '22/08/2008' UNION ALLSELECT 733289, '04/09/2008'SELECT *, DATEADD(DAY, v - 693596, '19000101') AS PesoFROM @Sample[/code]The "date" value of 693596 represent the date 3799-01-01 for some reason.You are 1899 years off! It seems like a prior conversion went wrong. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 07:32:54
|
when i try the above i get the error adding a value to datetime column caused overflow d |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 07:40:45
|
when i try the above i get the error adding a value to datetime column caused overflow d |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 07:46:19
|
| the original code isCONVERT(DATETIME, dbo.PROGRESS.Scheduled_to_Start - 693596) AS Tmp1 this fails i think because the datadbo.PROGRESS.Scheduled_to_Start is in type float and not a true intigerhowever when i try to convert it it doesnt work eitherCONVERT(DATETIME,(CONVERT(int, dbo.PROGRESS.Scheduled_to_Start) - 693596) AS Tmp1I get parsing errors and invalid syntaxHmmd |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 07:46:38
|
you mean running Peso's code as it is or against your database ?"adding a value to datetime column caused overflow"Check for any record with value less than 693596or use CASE WHEN to only convert if value is >= 693596SELECT CASE WHEN dbo.PROGRESS.Scheduled_to_Start>= 693596 THEN DATEADD(DAY, dbo.PROGRESS.Scheduled_to_Start - 693596, '19000101') ELSE NULL END AS Date KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 07:48:54
|
quote: Originally posted by Damian the original code isCONVERT(DATETIME, dbo.PROGRESS.Scheduled_to_Start - 693596) AS Tmp1 this fails i think because the datadbo.PROGRESS.Scheduled_to_Start is in type float and not a true intigerhowever when i try to convert it it doesnt work eitherCONVERT(DATETIME,(CONVERT(int, dbo.PROGRESS.Scheduled_to_Start) - 693596) AS Tmp1I get parsing errors and invalid syntaxHmmd
the parenthesis does not match. You missed out one ')' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Damian
Starting Member
12 Posts |
Posted - 2008-07-21 : 08:18:20
|
| added parenthesishowever results in arithmetic overflow againsorry about the double post updates slowly hereD |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-21 : 08:21:47
|
tried the query i Posted on 07/21/2008 : 07:46:38 ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Next Page
|