| Author |
Topic |
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 06:27:07
|
| Hi All,In MS-SQL server, I am executing a SQL task in a DTS package. This SQL task runs perfectly on one server but the same code fails on the other one prompting with this error message :"conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value".The Code in the SQL Task is :DECLARE @fileDate VARCHAR(10)DECLARE @timeID INTDECLARE @msg VARCHAR(100)--Extract the file date from the fileSELECT @fileDate = File_DateFROM Temp_Sales_DataWHERE RTRIM(RR_ID) = 'SALES ANALYSIS FOR' --format the value SET @fileDate = SUBSTRING(@fileDate, 5, 4) + '/' + SUBSTRING(@fileDate, 3, 2) + '/' + SUBSTRING(@fileDate, 1,2)--Select the approp. Time_IDSELECT @timeID = Time_ID FROM [Time] WHERE [Date] = convert(varchar(10), convert(smalldatetime, @fileDate), 20)--Insert the Time_IDUPDATE Temp_Sales_DataSET Time_ID = @timeID--Delete the header and footer records from the fileDELETE FROM Temp_Sales_DataWHERE RTRIM(RR_ID) IN ('SALES ANALYSIS FOR', 'END')--Check that the Time_ID has been assignedSELECT * FROM Temp_Sales_Data WHERE Time_ID IS NULLIF @@ROWCOUNT > 0BEGIN SELECT @msg = 'Time_ID not set correctly. Check that there is a suitable entry in the Time table' RAISERROR(@msg, 16, 1)ENDThe statement that creates the problem is :SELECT @timeID = Time_ID FROM [Time] WHERE [Date] = convert(varchar(10), convert(smalldatetime, @fileDate), 20)Does any one have a clue why this statment works perfectly on one server while fails on the other one ? |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-26 : 06:34:03
|
| Check the regional settings (date/time) on both the server, that may be the culprit.Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 06:49:24
|
| Well I have checked the Regional Date/Time settings too and they are same. Even I registered Both the servers on a single comp and executed the package but all in vain.Plz help!!! |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-26 : 07:19:36
|
Run the following command on both server and check the value for option "dateformat".EDIT: dbcc useroptions Sorry... my mistake !Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 07:35:10
|
| I think you forgot to mention the command. |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 07:45:51
|
| when I run the command dbcc useroptionsit displays me "mdy" for dateformat on one server and"dmy" for dateformat on the other server.Do I need to change the dateformat somewhere ? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-26 : 07:48:01
|
Try setting same dateformat on both servers like:set dateformat dmy orset dateformat mdy Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 08:08:21
|
| When I execute "set dateformat mdy" on query analyzer, it does change the value for dateformat but the effect is temporary i.e. when I close the query analyser and open it again the effect is gone.Even when I changed it in query analyzer and executed my DTS package the effect was not there, so I had to add the extra line "set dateformat mdy". This eventually solved the problem.Thanks Dude!!!Is there any way i can change the dateformat permanently ? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 08:28:17
|
what is the date format for @fileDate ? KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 08:30:07
|
quote:
SELECT @timeID = Time_ID FROM [Time] WHERE [Date] = convert(varchar(10), convert(smalldatetime, @fileDate), 20)
Why are you converting from varchar to smalldatetime and then back to varchar again ? What is the data type for column [Date] ? KH |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 08:35:46
|
| Its yyyy/mm/dd |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 08:40:34
|
quote: Originally posted by jasraja Its yyyy/mm/dd
then useconvert(smalldatetime, @fileDate, 111) KH |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 08:49:47
|
| that doesn't solves my problem. I still get the same error. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 08:57:02
|
Check your data. Make sure the date you form into @fileDate is of valid format and range KH |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-26 : 09:13:27
|
| The date is valid. As I quoted before, my code runs perfectly on one server but fails on other. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-26 : 09:19:31
|
you have not answer my the other quesions KH |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-26 : 09:22:30
|
quote: Is there any way i can change the dateformat permanently ?
The effect of SET DATEFORMAT only applies and last for the connection in which it is fired.The default dateformat depends on the default language selected for the server. If you permanently want to change the setting to say british date format (dmy), you can change the server's default language using sp_configure or EM.Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-26 : 09:34:52
|
| Dont worry on how dates are stored in sql server table. It is front end where youu need to show the date with different formats. When sending date to table, use universal format YYYYMMDD. To know how to query on dates, refer thishttp://sql-server-performance.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail |
 |
|
|
jasraja
Starting Member
22 Posts |
Posted - 2006-10-27 : 01:25:05
|
| Thanks Harsh and Madhivanan !!! |
 |
|
|
|