将nvarchar转换为int时转换失败

时间:2014-04-16 07:15:19

标签: sql sql-server xml

HI每个人都请帮帮我

我有存储过程

但是当它超越时,当将nvarchar转换为int时,它会导致异常转换失败,问题可能是什么。

在我的存储过程中,一个输入参数和一个输出参数,我需要导致测试变量已经在nvarchar数据类型而不是错误将转换失败怎么回事我不知道请帮助我,请解释我这是怎么回事所以,下次我照顾这个

ALTER PROCEDURE [dbo].[DirectMarketingbyBusiness_id] 
    -- Add the parameters for the stored procedure here
    (
            @business_id int,
            @test nvarchar(500) output

    )
    as
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    select 
    @test=

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkSmsText"]/@value)[1]','nvarchar(max)') =1
then  'SMS (text messaging),' end,'test,') +

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkliveTelelhoneText"]/@value)[1]','nvarchar(max)') =1
 then  'Live telephone calling,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkvoicebroadcastText"]/@value)[1]','nvarchar(max)') =1
 then  'Voice broadcast messaging,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkEmailText"]/@value)[1]','nvarchar(max)') =1
 then  'Email,' end,'test,') +

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkPostText"]/@value)[1]','nvarchar(max)') =1
 then  'Post,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkAnyOtherText"]/@value)[1]','nvarchar(max)') =1
 then  'chkAnyOtherText,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="TxtOtherText"]/@value)[1]','nvarchar(max)') <>''
 then  formXml.value('(/XmlDataPairDocument/dataitem[@id="TxtOtherText"]/@value)[1]','nvarchar(max)') end,'test') 




from tblRenewals
where 
business_id=@business_id and year=2014
return @test

END

1 个答案:

答案 0 :(得分:-1)

create PROCEDURE [dbo].[DirectMarketingbyBusiness_id] 
    -- Add the parameters for the stored procedure here
    (
            @business_id int,
            @test nvarchar(500) output

    )
    as
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    select 
    @test=

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkSmsText"]/@value)[1]','nvarchar(max)') =1
then  'SMS (text messaging),' end,'test,') +

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkliveTelelhoneText"]/@value)[1]','nvarchar(max)') =1
 then  'Live telephone calling,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkvoicebroadcastText"]/@value)[1]','nvarchar(max)') =1
 then  'Voice broadcast messaging,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkEmailText"]/@value)[1]','nvarchar(max)') =1
 then  'Email,' end,'test,') +

ISNULL(case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkPostText"]/@value)[1]','nvarchar(max)') =1
 then  'Post,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="chkAnyOtherText"]/@value)[1]','nvarchar(max)') =1
 then  'chkAnyOtherText,' end,'test,') +

ISNULL( case
 when formXml.value('(/XmlDataPairDocument/dataitem[@id="TxtOtherText"]/@value)[1]','nvarchar(max)') <>''
 then  formXml.value('(/XmlDataPairDocument/dataitem[@id="TxtOtherText"]/@value)[1]','nvarchar(max)') end,'test') 


 end

 exec [dbo].[DirectMarketingbyBusiness_id] 1, 'texttext'

执行存储过程。函数需要返回值。