Showing posts with label emailfromvarchar. Show all posts
Showing posts with label emailfromvarchar. Show all posts

Sunday, March 11, 2012

Error converting data type varchar to int.

can anyone see as to why I would get this error with the following SP?

ALTER PROCEDURE [dbo].[SP]@.IDint = 0,@.emailFromVARCHAR(50) =Null,@.emailDateVARCHAR(50) =Null,@.emailSubjVARCHAR(50) =Null,@.emailTxtBodyVARCHAR(1000) =Null,@.emailHtmlBodyVARCHAR(1000) =NullAS-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;DECLARE @.NotesVARCHAR (8000)DECLARE @.TicketIDINTDECLARE @.emailBodyVARCHAR (1000)DECLARE @.LengthIntSET @.Notes =''SET @.Length =LEN(@.emailSubj)-- insert a new entryINSERT INTO PopEmail ( emailFrom, emailDate, emailSubj, emailTxtBody, emailHtmlBody )VALUES ( @.emailFrom, @.emailDate, @.emailSubj, @.emailTxtBody, @.emailHtmlBody )-- get the new IDSET @.ID =@.@.identityIf ( @.ID <> 0 )AND (ISNUMERIC(@.emailSubj) = 1 )BeginIF @.emailTxtBodyISNULLBEGINSet @.emailBody = @.emailHtmlBodyPRINT'@.emailHtmlBody: ' + @.emailBodyENDELSEBEGINSET @.emailBody = @.emailTxtBodyPRINT'@.emailTxtBody: ' + @.emailBodyENDSET @.TicketID =CAST( @.emailSubjAS int )SET @.Notes = @.emailFrom +', ' + @.emailDate +', ' + @.emailBodySelect @.ID = IDFrom TicketDetailsWhere TicketDetails.TicketID = @.TicketIDExec differentSP @.ID, @.TicketID, @.NotesPRINT'Subject: [' + @.emailSubj +']'print'length: ' +CAST(@.Lengthas varchar (10))Print'emailSubj: ' +CAST( @.emailSubjAS int )PRINT'ID: ' +Cast( @.IDas varchar ( 10 ) )PRINT'TicketID: ' +Cast( @.TicketIDAS Varchar ( 10 ) )PRINT'Notes: ' + @.NotesPRINT'ID: ' +Cast( @.IDas varchar ( 10 ) )ENDELSEBEGINPrint'ID: ' +CAST(@.IDAS VarChar(10))PRINT'ISNUMERIC: ' +CAST(ISNUMERIC(@.emailSubj)AS VarChar (10))PRINT'Subject: [' + @.emailSubj +']'END

Which line caused this error? I found at least this line was wrong:

Print'emailSubj: ' +CAST( @.emailSubjAS int )

Should be

Print'emailSubj: ' +CAST( @.emailSubjAS Varchar(10) )

|||

I found that I am just new and prone to making mistakes... The SP that I am calling has several variables that it is looking for, and the @.Notes variable is not until the end of the list. So my call of the SP should look like this:

EXEC someSP @.ID, @.TicketID, , , , , @.Notes.

Now she works... ahhhh the joys of learning.

Thanks,

CK