日期:2014-05-18 浏览次数:20423 次
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go CREATE PROC [dbo].[AddAccountInfo]( @userName varchar(50), @password varchar(50), @TMStamp bigint, @sync_id int ) as begin declare @sql varchar(500) set @sql='insert into AccountInfo values('+@userName+','+@password+','+@TMStamp+','+@sync_id+')' print @sql end
set @sql='insert into AccountInfo values('''+@userName+''','''+@password+''','+@TMStamp+','+@sync_id+')'
exec AddAccountInfo 'aa','xx',1,1 消息 8114,级别 16,状态 5,过程 AddAccountInfo,第 12 行 从数据类型 varchar 转换为 bigint 时出错。
set @sql='insert into AccountInfo values('+@userName+','+@password+','+cast(@TMStamp as varchar(100))+','+cast(@sync_id as varchar(100))+')'
------解决方案--------------------
樓上各位都误导LZ了,变量要不要加引号要看情况,不是絕對的,像下面这种情况就要加引号
set @sql='insert into AccountInfo values('''+@userName+''','''+@password+''','''+cast(@TMStamp as varchar(100))+''','''+cast(@sync_id as varchar(100))+''')' Exec (@sql)