set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[IntoUser]
AS
BEGIN
SET NOCOUNT ON; Declare @Count Int declare @code1 varchar(50)SET @Count=1
WHILE @Count<=200
BEGIN
set @code1='fox' +@count
INSERT INTO tb_user(code,pwd,tag,state,viewcount,count) VALUES(@code1,@Count,@Count,@Count,@Count,@Count)
set @CreateDate = getdate ()
SET @Count=@Count+1
END
END
编译通过说执行的时候
消息 245,级别 16,状态 1,过程 IntoUser,第 13 行
在将 varchar 值 'fox' 转换成数据类型 int 时失败
set QUOTED_IDENTIFIER ON
go
ALTER proc [dbo].[IntoUser]
AS
BEGIN
SET NOCOUNT ON; Declare @Count Int declare @code1 varchar(50)SET @Count=1
WHILE @Count<=200
BEGIN
set @code1='fox' +@count
INSERT INTO tb_user(code,pwd,tag,state,viewcount,count) VALUES(@code1,@Count,@Count,@Count,@Count,@Count)
set @CreateDate = getdate ()
SET @Count=@Count+1
END
END
编译通过说执行的时候
消息 245,级别 16,状态 1,过程 IntoUser,第 13 行
在将 varchar 值 'fox' 转换成数据类型 int 时失败
改成 set @code1='fox' +convert(varchar(20),@count ) 试试
set @code1='fox' +rtrim(@count)
转化为字符串型,
例如:declare @I int
set @I=562
select right(('10000'+ltrim(str(@I))),4)