Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2005, 05:01 PM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Conversion issue

Hi Everyone

I m trying to convert the data of one table into two tables i.e. if the data is valid it needs to be dumped into VALID table else into ERROR table but i m encountering following error while casting during select "Syntax error converting the varchar value '$ED(RSNYRC_M,' to a column of data type int."

The reason is that the tblEmpsxDailyExc_HIST table cotains lot of invalid values .

So please can someone help me out how to handle this problem that at the time of select itself if the value is not of proper data format i can dump that row into ERRROR table.

CREATE PROCEDURE uspTransferDATAEXC
AS

DECLARE @Date datetime
DECLARE @Office varchar(50)
DECLARE @AgentPin char(4)
DECLARE @AgentSSN int
DECLARE @AgentName varchar(50)
DECLARE @CodeType varchar(50)
DECLARE @Code varchar(50)
DECLARE @VarDuration varchar(50)
DECLARE @Duration int
DECLARE @CreatedDate datetime


DECLARE CursorEXC CURSOR FOR

SELECT cast([Date] as datetime),
    Office,
    cast(AgentPin as char(4)),
    cast(AgentSSN as int),
    AgentName,
    CodeType,Code,VarDuration,
    cast(Duration as int),
    CreatedDate

FROM tblEmpsxDailyExc_HIST



OPEN CursorEXC

FETCH NEXT FROM CursorEXC INTO

@Date,@office,@AgentPin,@AgentSSN,@AgentName,
@CodeType, @Code, @VarDuration, @Duration, @CreatedDate

WHILE(@@FETCH_STATUS = 0)

BEGIN

IF
    (isdate(@Date)=1) AND
    @Office IS NOT NULL AND
    @AgentPin IS NOT NULL AND
    (isnumeric(@AgentSSN)=1) AND
    @AgentName IS NOT NULL AND
    @CodeType is NOT NULL AND
    @Code is NOT NULL AND
    @VarDuration IS NOT NULL AND
    (isnumeric(@Duration)=1) AND
    (isdate(@CreatedDate)=1)

INSERT INTO tblEmpsxDailyExc_VALID([Date],Office,AgentPin,
AgentSSN,AgentName,CodeType,Code, VarDuration, Duration,CreatedDate)

VALUES(@Date,@office,@AgentPin,@AgentSSN,@AgentNam e,
@CodeType, @Code, @VarDuration, @Duration, @CreatedDate)

ELSE

INSERT INTO tblEmpsxDailyExc_ERROR([Date],Office,AgentPin,
AgentSSN,AgentName,CodeType,Code, VarDuration, Duration,CreatedDate)

VALUES(@Date,@office,@AgentPin,@AgentSSN,@AgentNam e,
@CodeType, @Code, @VarDuration, @Duration, @CreatedDate)

FETCH NEXT FROM CursorEXC INTO

@Date,@office,@AgentPin,@AgentSSN,@AgentName,
@CodeType, @Code, @VarDuration, @Duration, @CreatedDate


END

CLOSE CursorEXC
DEALLOCATE CursorEXC
GO





Similar Threads
Thread Thread Starter Forum Replies Last Post
Data conversion Neal SQL Server 2000 4 May 30th, 2007 11:01 AM
Date conversion Issue dhay1999 Access 2 May 30th, 2007 06:47 AM
Database conversion issue prashantlakhlani SQL Server 2005 1 August 26th, 2006 11:46 AM
Data Type Conversion using WHERE IN () Colonel Angus SQL Server 2000 14 August 18th, 2004 08:08 PM
Data Type Conversion owain SQL Language 5 October 31st, 2003 12:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.