日期:2014-05-17  浏览次数:23241 次

在将 varchar 值 ','' 转换成数据类型 int 时失败。
写了一个存储过程出现如上错误:在将 varchar 值 ','' 转换成数据类型 int 时失败。
创建数据表sql如下:

CREATE TABLE [dbo].[hx_business_record20110901](
[hx_business_id] [bigint] NOT NULL,
[hx_business_account] [nvarchar](25) NULL,
[hx_prepaid_password] [nvarchar](100) NULL,
[hx_prepaid_flag] [int] NULL,
[hx_business_transaction] [nvarchar](10) NULL,
[hx_business_money] [nvarchar](12) NULL,
[hx_business_money_flag] [nvarchar](20) NULL,
[hx_business_datetime] [nvarchar](25) NULL,
[hx_business_mark] [nvarchar](25) NULL,
[hx_merchant_number] [nvarchar](20) NULL,
[hx_merchant_category] [int] NULL,
[hx_business_accept] [nvarchar](10) NULL,
[hx_card_number] [nvarchar](10) NULL,
[hx_business_createtime] [datetime] NULL,
[hx_business_status] [int] NULL,
[hx_business_content] [nvarchar](10) NULL,
[hx_business_distribution] [int] NULL
) ON [PRIMARY]
GO

创建存储过程如下:

ALTER PROCEDURE [dbo].[hx_business_record_ADD] 
@tableName varchar(50),
    @hx_business_id bigint,
@hx_business_account nvarchar(25),
@hx_prepaid_password nvarchar(100),
@hx_prepaid_flag int,
@hx_business_transaction nvarchar(10),
@hx_business_money nvarchar(10),
@hx_business_money_flag nvarchar(20),
@hx_business_datetime nvarchar(25),
@hx_business_mark nvarchar(25),
@hx_merchant_number nvarchar(20),
@hx_merchant_category int,
@hx_business_accept nvarchar(10),
@hx_card_number nvarchar(10),
@hx_business_createtime datetime,
@hx_business_status int,
@hx_business_content nvarchar(10),
@hx_business_distribution int   
AS
BEGIN
SET NOCOUNT ON;
        begin transaction
--插入记录 
declare @sql nvarchar(max)
set @sql = N'INSERT INTO '+@tableName+'
(
[hx_business_id],[hx_business_account],[hx_prepaid_password],
[hx_prepaid_flag],[hx_business_transaction],[hx_business_money],
[hx_business_money_flag],[hx_business_datetime],[hx_business_mark],
[hx_merchant_number],[hx_merchant_category],[hx_business_accept],
[hx_card_number],[hx_business_createtime],[hx_business_status],
[hx_business_content],[hx_business_distribution]
 )
 VALUES
 (  '+ltrim(@hx_business_id)+',
'''+isnull(@hx_business_account,null)+''',