| Author | Topic | 
                            
                                    | srishaStarting Member
 
 
                                        38 Posts | 
                                            
                                            |  Posted - 2013-06-06 : 02:32:20 
 |  
                                            | select year(POSTDATE) from OEINVHPostdate column is in date datatype.ErrorMsg 8115, Level 16, State 2, Line 2Arithmetic overflow error converting expression to data type datetime.SRISHA |  | 
       
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 02:36:56 
 |  
                                          | Sorry I dont think so. If postdate is of date datatype and if you're using above query i dont think it will cause any overflow as it doesnt require any conversion to datetime againMy guess is you're using another query over this to make it back to datetime which is where overflow occurs due to some unexpected values.Can you post the full query please?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 02:40:31 
 |  
                                          | Try this one... let us know the outputSELECT convert(varchar(4),POSTDATE,112) FROM OEINVH--Chandu |  
                                          |  |  | 
                            
                       
                          
                            
                                    | srishaStarting Member
 
 
                                    38 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 02:48:38 
 |  
                                          | Msg 8115, Level 16, State 5, Line 3Arithmetic overflow error converting numeric to data type varchar.Same error comes upSRISHA |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 02:51:41 
 |  
                                          | quote:are you sure POSTDATE is date?check it firstOriginally posted by srisha
 Msg 8115, Level 16, State 5, Line 3Arithmetic overflow error converting numeric to data type varchar.Same error comes upSRISHA
 
 SELECT DATA_TYPEFROM INFORMATION_SCHEMA.COLUMNSWHERE TABLE_NAME = 'OEINVH'AND COLUMN_NAME = 'POSTDATE'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | srishaStarting Member
 
 
                                    38 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 02:57:49 
 |  
                                          | Sorry it is in decimal data type --------------------------BYSRISHA |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:03:05 
 |  
                                          | ok. that explains. so whats the value contained in it? is it full date in YYYYMMDD fomat?if yes ,use SELECT YEAR(CAST(POSTDATE AS date)) FROM OEINVHif it just contains a decimal value indicating daysuse SELECT YEAR(DATEADD(dd,POSTDATE,0)) FROM OEINVH------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:03:48 
 |  
                                          | quote:then in which format date is stored?--ChanduOriginally posted by srisha
 Sorry it is in decimal data type --------------------------BYSRISHA
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:03:48 
 |  
                                          | This also explains why its important that you use proper datatype for your fields------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | srishaStarting Member
 
 
                                    38 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:07:07 
 |  
                                          | yes,it is stored in yyyymmdd format.If i use first  query ,it shows the following error msgMsg 529, Level 16, State 2, Line 1Explicit conversion from data type decimal to date is not allowed.--------------------------BYSRISHA |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:10:00 
 |  
                                          | quote:Originally posted by srisha
 yes,it is stored in yyyymmdd format.If i use first  query ,it shows the following error msgMsg 529, Level 16, State 2, Line 1Explicit conversion from data type decimal to date is not allowed.--------------------------BYSRISHA
 
 SELECT YEAR(CAST(POSTDATE AS datetime)) FROM OEINVH------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | srishaStarting Member
 
 
                                    38 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:12:44 
 |  
                                          | when i using above query following error arrives,Msg 8115, Level 16, State 2, Line 2Arithmetic overflow error converting expression to data type datetime.--------------------------BYSRISHA |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:15:26 
 |  
                                          | quote:then i guess you've some spurious valueswhat does this return?Originally posted by srisha
 when i using above query following error arrives,Msg 8115, Level 16, State 2, Line 2Arithmetic overflow error converting expression to data type datetime.--------------------------BYSRISHA
 
 SELECT POSTDATE FROM OEINVHWHERE ISDATE(POSTDATE) = 0OR LEN(POSTDATE) < 8------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |  
                                          |  |  | 
                            
                       
                          
                            
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:20:39 
 |  
                                          | hi srisha,-- see this illustrationDECLARE @yourDate DECIMAL (8)SET @yourDate = 20130606SELECT LEFT(@yourDate, 4)  -- 2013--Chandu |  
                                          |  |  | 
                            
                       
                          
                            
                                    | srishaStarting Member
 
 
                                    38 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:21:07 
 |  
                                          | SELECT POSTDATE FROM OEINVHWHERE ISDATE(POSTDATE) = 1and LEN(POSTDATE) < 10it working when i use above coding .i need only year part from the value--------------------------BYSRISHA |  
                                          |  |  | 
                            
                       
                          
                            
                                    | bandiMaster Smack Fu Yak Hacker
 
 
                                    2242 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 03:24:06 
 |  
                                          | quote:--ChanduOriginally posted by srisha
 SELECT LEFT(POSTDATE, 4) FROM OEINVHWHERE ISDATE(POSTDATE) = 1and LEN(POSTDATE) < 10it working when i use above coding .i need only year part from the value--------------------------BYSRISHA
 
 |  
                                          |  |  | 
                            
                       
                          
                            
                                    | visakh16Very Important crosS Applying yaK Herder
 
 
                                    52326 Posts | 
                                        
                                          |  Posted - 2013-06-06 : 04:00:36 
 |  
                                          | quote:why 10?do you've other date formats also available? ALso LEN(POSTDATE) < 10 has a potential problem that it may return incomplete date values too which will still return 1 for ISDATE. But if you're only concerned about year part then you're good to go with thishttp://visakhm.blogspot.com/2013/05/enforcing-effective-data-validation.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogsOriginally posted by srisha
 SELECT POSTDATE FROM OEINVHWHERE ISDATE(POSTDATE) = 1and LEN(POSTDATE) < 10it working when i use above coding .i need only year part from the value--------------------------BYSRISHA
 
 |  
                                          |  |  | 
                            
                            
                                |  |