Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL 2000 to SQL 2012 Stored Procedure issue

Posted on 2014-04-07
2
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

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

ALTER                                       PROC [dbo].[usp_UpdateInteriorDC]

to

ALTER                                       PROCEDURE dbo.usp_UpdateInteriorDC
0
 
LVL 70

Expert Comment

by:Scott Pletcher
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

596 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