Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i executing below query..some error is throwing..


SQL
insert into Tbl_leave_setting

select top 2 ROW_NUMBER() over(order by t.empcode),convert(datetime,t.dates),
t.empcode,t.types,t.anual,t.anual from
(
SELECT GETDATE() dates,[emp code] empcode,2 types,[annual] anual FROM MEGLEAVE
union all
SELECT getdate(),[emp code] ,3,[sick] FROM MEGLEAVE
)t
where t.anual is not null
order by t.empcode




Msg 232, Level 16, State 2, Line 1
Arithmetic overflow error for type varchar, value = 81002170.000000.
The statement has been terminated.
Posted

1 solution

It is difficult to help you without knowing the table structures or seeing some sample data. However here are a couple of steps for you to find out where the problem is.

1. Highlight
SQL
SELECT GETDATE() dates,[emp code] empcode,2 types,[annual] anual FROM MEGLEAVE
and run (F5) just that section - does the error occur?

2. Do the same with
SQL
SELECT getdate(),[emp code] ,3,[sick] FROM MEGLEAVE
- does the error occur?

3. The error is most likely to be caused because one of the columns in Tbl_leave_setting is declared as Varchar(x) where x is less than 15

4. Have a look at convert(datetime,t.dates) - what type is column t.dates? - if you are trying to store a Date then it should be of type Date or at least DateTime in which case there is no need for the Convert.

Always use the most appropriate Type for the data you are trying to store, don't use Varchar (or Nvarchar, char or nchar) for anything other than alphanumeric data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900