Solved

SQL 2000 to SQL 2012 Stored Procedure issue

Posted on 2014-04-07
2
279 Views
Last Modified: 2014-04-24
Below is the Stored Procedure that worked in SQL 2000, but in SQL 2012 throws error -
"Msg 241, Level 16, State 1, Procedure usp_UpdateInteriorDC, Line 51
Conversion failed when converting date and/or time from character string."


USE [ABCDEF]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER                                       PROC [dbo].[usp_UpdateInteriorDC]
      @intInteriorTransID INTEGER ,
      @chvIssueDate VARCHAR(20),
      @chvRevDate VARCHAR(20) ,
      @chvItemDescription VARCHAR(100),
      @intManufacturerID INTEGER ,
      @chvManufacturerFOB      VARCHAR(50),
      @chvManufacturerLeadTime VARCHAR(20),
      @intFurnishedInstalledFlag INTEGER ,
      @chvSpecialNotations VARCHAR(2000),
      @intUserID INTEGER,
      @chvRevisionNotes VARCHAR(255),
      @intMainInteriorID INTEGER ,
      @chvModifiedTime VARCHAR(20),
      @chrErrCode CHAR(1) OUTPUT,
      @chvErrMsg VARCHAR(200) OUTPUT
AS
DECLARE @chvCurRevDate VARCHAR(20)
BEGIN

      IF @chvRevDate IS NOT NULL AND  @chvRevDate <> ''
            SET @chvCurRevDate = @chvRevDate

      /* Insert Trans Master details based on values passed
         and values generated */
      UPDATE ICS_Interior_Trans_Master
            SET Issue_date = @chvIssueDate,
            Rev_Date = ISNULL(@chvCurRevDate,Rev_Date),
            Item_Description = @chvItemDescription,
            Manufacturer_ID = @intManufacturerID,
            Manufacturer_FOB = @chvManufacturerFOB,
            Manufacturer_Leadtime = @chvManufacturerLeadtime,
            Furnished_Installed_Flag =@intFurnishedInstalledFlag,
            Special_Notations = @chvSpecialNotations,
            Revision_Notes =@chvRevisionNotes,
            Modified_By = @intUserId,
            Modified_Datetime = GetDate()
      WHERE
            Interior_Trans_ID = @intInteriorTransID      AND
            CONVERT(VARCHAR(20), Modified_DateTime,113) = CONVERT(VARCHAR(20), @chvModifiedTime,113)
            

      IF @@ERROR = 0
      BEGIN
            SET @chrErrCode = '0'
            SET @chvErrMsg = dbo.FNGETErrorMessage('ER014')
      END
      ELSE
      BEGIN
            SET @chrErrCode = '2'
            SET @chvErrMsg       =  dbo.FNGETErrorMessage('ER008')
            RETURN
      END

END

I've tried changing the Datetime format, but would appreciate hearing if someone can see what it's issue is????

Thank you,
0
Comment
Question by:urthrilled
2 Comments
 
LVL 6

Accepted Solution

by:
Ryan Smith earned 500 total points
ID: 39983694
Change this:

ALTER                                       PROC [dbo].[usp_UpdateInteriorDC]

to

ALTER                                       PROCEDURE dbo.usp_UpdateInteriorDC
0
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 39983711
Most likely the input value for @chvModifiedTime is not in a valid format.  20 characters is not enough bytes to hold the full string value of format 113, which is "dd mon yyyy hh:mi:ss.mmm".  A first quick shot would be to increase the length of @chvModifiedTime to at least 24 bytes.  The CONVERT in the SELECT will strip the ms anyway.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now