本文介绍了将int转换为数据类型numeric的算术溢出错误。 - 如何将Int转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码会将Int抛出数字转换错误。
请帮帮我。
Hi,
The following code throws "Int" to "numeric" conversion error.
Please help me out.
Begin
declare @tmptble TABLE(EmpId nvarchar(10),EmpMonth numeric(2,0),EmpYear numeric(4,0))
insert into @tmptble(EmpId,EmpMonth,EmpYear)
select emp_CDSID,MONTH(getdate()),YEAR(getdate()) from Employee
declare @count numeric(2,0)
declare @empid nvarchar(10)
declare @month numeric(2,0)
declare @year numeric(4,0)
set @count = (select count(*) from @tmptble)
declare FirstCursor cursor for select EmpId,EmpMonth,EmpYear from @tmptble
open FirstCursor
while (@count>0)
begin
fetch FirstCursor into @empid,@month,@year
set @existsAttendance = (select count(*) from Attendance where EmpId=@empid and EmpMonth=@month and EmpYear=@year)
-- [ ATTENDANCE INSERT ] --
if (@existsAttendance = 0)
begin
Insert into CDSI_DB.dbo.Attendance(EmpId,EmpMonth,EmpYear,SG,S1,S2,W,W1,W2,LOP,CO,SPL,OD,H) values(UPPER(@empid),@month,@year,0,0,0,0,0,0,0,0,0,0,0)
end
set @count=@count-1
end
close FirstCursor
End
并且,出勤表将EmpMonth和EmpYear作为数值数据类型。
And, "Attendance table has EmpMonth and EmpYear as numeric datatype.
推荐答案
declare @tmptble TABLE(Col1 nvarchar(10),Col2 INT,Col3 INT)
insert into @tmptble(Col1,Col2,Col3)
select ID, MONTH(getdate()), YEAR(getdate())
from Employee
[]和 []功能返回整数数据类型;)
Month[^] and Year[^] funtion return Integer data type ;)
declare @count numeric(2,0)
发生了吗?计数大于99?
Did it happen that the count was greater than 99?
这篇关于将int转换为数据类型numeric的算术溢出错误。 - 如何将Int转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!