set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
goCREATE PROC [dbo].[AddAccountInfo](
@userName varchar(50),
@password varchar(50),
@TMStamp bigint,
@sync_id int
)
as
begindeclare @sql varchar(500)
set @sql='insert into AccountInfo values('+@userName+','+@password+','+@TMStamp+','+@sync_id+')'
print @sql
endset @sql='insert into AccountInfo values('''+@userName+''','''+@password+''','+@TMStamp+','+@sync_id+')'@userName和@password是varchar类型,前后应该 几个,号啊,怎么老报错啊
exec AddAccountInfo 'aa','xx',1,1消息 8114,级别 16,状态 5,过程 AddAccountInfo,第 12 行
从数据类型 varchar 转换为 bigint 时出错。
insert into AccountInfo values(@userName,@password,@TMStamp,@sync_id)
这样不就可以了,不过列要对上号。
set @sql='insert into AccountInfo values('+@userName+','+@password+','+cast(@TMStamp as varchar(100))+','+cast(@sync_id as varchar(100))+')'
set @sql='insert into AccountInfo values('+@userName+','+@password+','+cast(@TMStamp as varchar(100))+','+cast(@sync_id as varchar(100))+')' 结果
insert into AccountInfo values(sfwe,xx,1,1)
消息 128,级别 15,状态 1,第 1 行
在此上下文中不允许使用名称 "sfwe"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名
CREATE PROC [dbo].[AddAccountInfo](
@userName varchar(50),
@password varchar(50),
@TMStamp bigint,
@sync_id int
)
as
begin
insert into AccountInfo values(@userName,@password,@TMStamp,@sync_id)
end