0

HI Every one please help me

I have stored procedure

but when it is exceutate it getting excepition coversion failed when convert nvarchar to int what is the problem may.

In my stored procedure one input parameter and one output parameter and i need result in test variable that is already in nvarchar datatype rather than the error will be converting failed how is happend i dont know please help me and please explain me how this happend so next time i take care for this

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

5
  • 1
    Try taking the source code out of the stored procedure, and run it in SSMS, and see were it is giving you the error. We do not have access to formXml - so it would be quite difficult to pinpoint your problem - but it seems the value of the function and the "=1" is a potential problem.
    – Mez
    Apr 16, 2014 at 7:18
  • when i run this sp to ssms then it is working fine Apr 16, 2014 at 7:21
  • and here the code on my .net Apr 16, 2014 at 7:23
  • command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@test", SqlDbType.NVarChar ,50); command.Parameters["@test"].Direction = ParameterDirection.Output; command.Parameters.AddWithValue("@business_id", oBusinesse.id); command.ExecuteNonQuery(); direct = (string)command.Parameters["@test"].Value; Apr 16, 2014 at 7:24
  • is oBusinesse.id an integer? If yes try setting the parameter when passing the parameter from the application, with an integer data type.
    – Mez
    Apr 16, 2014 at 7:26

1 Answer 1

-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'

Stored procedures are executed. Functions require to return values.

1
  • I m not clear with your answer please explain me details what you want to tell to me Apr 16, 2014 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.