+连接符 连接两个数字字符串出现 溢出了整数列的问题
declare @GuID varchar(8000)
set @GuID= '330203000 '+ '013 '
出现
:转换 varchar 值 '330203000013 ' 时溢出了整数列。超过了其中最大的整数值。
不知道为啥?
------解决方案--------------------把int改为bigint
------解决方案--------------------直接定義為varchar沒有問題啊。
Create function getGuId
(
@class varchar(50),
@newsDate varchar(500),
@id varchar(50)
)
RETURNS varchar(5000)
as
begin
declare @GuID varchar(8000),@tempID varchar(500)
declare @GuIDBigInt varchar(8000)
set @GuIDBigInt= '330203000 '+ '000000000000033 '
set @GuIDBigInt=Cast(@GuIDBigInt as varchar(50))+cast(year(@newsDate) as varchar(50))
if len(@id) <7
begin
declare @i as int
declare @numZero as int
set @numZero=7-len(@id)
set @i=1
while @i <=@numZero
begin
set @id= '0 '+@id
set @i=@i+1
end
end
set @GuID=cast(@GuIDBigInt as varchar(100))+cast(@id as varchar(100))
--
-- set @GuID=cast(@GuIDBigInt as varchar(100))
return @GuID
end
GO
Select dbo.getGuId( '1 ', '20070509 ', '1 ')
GO
Drop Function getGuId