Showing posts with label numeric. Show all posts
Showing posts with label numeric. Show all posts

Sunday, March 11, 2012

error converting varchar to numeric

i have a huge stored procedure abt 500 lines..and i am calling this sp from an asp.net page...thn i got this error - error converting varchar to numeric - and am trying to debug...is there any way we can find out where the error is coming from...like aproxly which line number..etcor do i have to go through each line manually and see where i am doing the conversion...

thanksNever tried it myself but it should let you step through a sproc like you would your C#/VB.Net code behind.

Walkthrough: Debugging Hello World, a SQL Stored Procedure|||hi MMS

I was able to isolate the line tht was causing the problem..however i will go through the article to see if it will help with some info for future use.

thanks.

error converting nvarchar to int


I have this stored procedure and am getting errors.
I filtered on Info = 'I' which should only have numeric values. I have some
info with Info = 'L' that does have alpha code.
I have tried the case below but am still having problems.
Any help appreciated
CREATE PROCEDURE NTF_UpdateInfoAfterPost
@.orderNo varchar(30),
@.rUser int
AS
--Used to delete the Info messages from all users.
--Typically used before creating a new info message
update Notify
Set
signed = 4,
rUser = @.rUser,
DateSigned = GetDate()
where (Info = 'I' and Info is not null) and orderNo = Case When
isNumeric(@.OrderNo) = 1 then @.OrderNo Else 0 End
Stephen K. MiyasatoHi
Try
update Notify
Set
signed = 4,
rUser = @.rUser,
DateSigned = GetDate()
where (Info = 'I' and Info is not null) and orderNo = Case When
isNumeric(@.OrderNo) = 1 then @.OrderNo Else '0' End
"Stephen K. Miyasato" <miyasat@.flex.com> wrote in message
news:%23IxODu4gGHA.1792@.TK2MSFTNGP03.phx.gbl...
>
> I have this stored procedure and am getting errors.
> I filtered on Info = 'I' which should only have numeric values. I have
> some info with Info = 'L' that does have alpha code.
> I have tried the case below but am still having problems.
> Any help appreciated
>
> CREATE PROCEDURE NTF_UpdateInfoAfterPost
> @.orderNo varchar(30),
> @.rUser int
> AS
> --Used to delete the Info messages from all users.
> --Typically used before creating a new info message
> update Notify
> Set
> signed = 4,
> rUser = @.rUser,
> DateSigned = GetDate()
> where (Info = 'I' and Info is not null) and orderNo = Case When
> isNumeric(@.OrderNo) = 1 then @.OrderNo Else 0 End
> Stephen K. Miyasato
>

Error converting data type varchar to numeric.

DECLARE @.ENTITY nvarchar (100)

set @.ENTITY = 'AccidentDimension'

DECLARE @.FIELD nvarchar (100)

set @.FIELD = 'JurisdictionState'

DECLARE @.KEYID nvarchar (100)

SET @.KEYID = '1234567890'

DECLARE @.VALUE nvarchar (100)

SET @.VALUE = 'WI'

DECLARE @.WC_TABLE NVARCHAR(100)

SET @.WC_TABLE = 'WorkingCopyAdd' + @.ENTITY

DECLARE @.SQL1 NVARCHAR (1000)

SET @.SQL1 = 'INSERT INTO ' + @.WC_TABLE+ ' (Claim, '+ @.Field +') VALUES ('''+ @.KEYID +''', '''+@.VALUE+''')'

EXECUTE sp_executesql @.SQL1

Can somebody help me. I get this error:

Error converting data type varchar to numeric.

while executing this Dynamic TSQl Command

Odd; what is the data type of the "JurisdictionState" column. The other column should be fine, but also what is the data type of the "Claim" column.

|||

The statement you are executing is

INSERT INTO WorkingCopyAddAccidentDimension (Claim, JurisdictionState) VALUES ('1234567890', 'WI')

There is a bigger question than the varchar/numeric conversion, and that is why you are using dynamic SQL, but to answer the question you asked, it doesn't look like there should be a problem. Is this the exact code that is failing, or might it be failing on another @.KEYID value?

I suggest you look at www.sommarskog.se/dynamic_sql.html for more on dynamic SQL, even thought it's tangential to your specific question here.

Steve Kass

Drew University

http://www.stevekass.com

|||

Claim is of type: varchar

JurisdictionState is char of length 2

I seperated and inserted with each colunm at a time to know if its problem with Claim or JursidictionState. Well, both of the time I received same error.

|||The error may be caused by an incorrect default, as in teh following sample:

CREATE TABLE a(i int, j INT DEFAULT('acs'))
GO
INSERT a(i)VALUES(1)

also the error might be caused by a trigger. Do you have triggers on the table?|||

Well I had DEFAULT ' ' (A Blank / Space)

Is this the problem ?

|||

yes.. yes..

Always try to stick with the column datatype while giving the default value..

I am really wondering how SQL Server allows to create the default value with different datatype..

|||

CREATE TABLE WCAddAcciDim

([Claim] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS DEFAULT ' ',

[JurisdictionState] [char](2) COLLATE SQL_Latin1_General_CP1_CI_AS DEFAULT ' '

)

GO

INSERT dbo.WCAddAcciDim(Claim , JurisdictionState)VALUES('12', 'IN')

INSERT dbo.WCAddAcciDim(Claim , JurisdictionState)VALUES('1234567890', 'WI')

select * from WCAddAcciDim

DROP TABLE WCAddAcciDim

Well I see no problem when I execute this.

And when I execute this below line, just this line, without use of Dynamic SQL

INSERT dbo.WorkingCopyAddAccidentDimension(Claim, JurisdictionState) VALUES ('1234567890', 'WI')

I get error.

Very Strange.

I created teh table WorkingCopyAddAccidentDimension same way as I did above, infact I copied those lines and rename the tabel name thats it.

What might be the Hidden error, Any idea please

|||

What is the error message you are getting… Verify the table schema using..

Sp_help WorkingCopyAddAccidentDimensiona

|||

Mani:

When I removed the Defaults I was able to update and Insert as wanted and required. However i have NULLS in the rest of colunm. This table has 68 Colunms and I have multiple tables around 6of similar number of colunms. Now I am using the data from these Staging/ WorkingCopy tables and Inserting it back to main Table. Where certain colunm cannot be null. If there is a null in certain colunm it will not allow me to insert it. Thast why I chose to make BLANK as a default in WorkingCopy Table.

Now that I have remove BLANK/ SPACE from teh default, is there any Standard way of Replacing these NULLS with the Blank /Space. Could you please suggest any way to do this?

What does MS SQL Standards have to say on this?

What I could think of is to replace each colunm with a space were ever there is NULL but I guess this is not the standard way of doing. Any suggestion or any modification on re-creating WorkingCopy Table with Defaults?

|||

You are in wrong direction, The default won’t help you here..

The default only activated when you have no entry on the INSERT statement. When you try to INSERT the NULL value the Default value will not be taken, rather it will store as NULL.

In single word, the DEFAULT value only stored when there is no value/no entry specified in the insert query…

As per the BOL,

Column definition

No entry, no DEFAULT definition

No entry, DEFAULT definition

Enter a null value

Allows null values

NULL

Default value

NULL

Disallows null values

Error

Default value

Error

So, you have to use the ISNULL function to fix your problem.

Code Snippet

Create table #Staging1

(

Id int,

Name varchar(10)

)

Insert Into #Staging1 Values(1, NULL);

Insert Into #Staging1 Values(1, 'test');

Go

Create table #Main

(

ID int NOT NULL,

Name varchar(10) NOT NULL DEFAULT ('')

);

--Will Work Fine

Insert Into #Main(ID)

Select ID From #Staging1

--Should Fail

Insert Into #Main(ID,Name)

Select ID,Name From #Staging1

--Will Work

Insert Into #Main(ID,Name)

Select ID,Isnull(Name,'') From #Staging1

|||

Excellent

Got it

Thanks a lot Mani

Error converting data type varchar to numeric.

HI
i have a very big problem.
i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
this is my code

case when Revenue='A' then Sum(total_amt) else ' ' end as A

but it is giving me and error Error converting data type varchar to numeric.
please help

Quote:

Originally Posted by voroojak

HI
i have a very big problem.
i have a cloumn name Revenue and i have differt types of revenue in it such as A, B, C.
what i want to do is that i want to say that when the Revenue column is A then sum the tola mount and put in in a new column name A when b then again same thing.
this is my code

case when Revenue='A' then Sum(total_amt) else ' ' end as A

but it is giving me and error Error converting data type varchar to numeric.
please help


first, why the error.

because your case statement said when revenue = 'A' return the sum of total_amt else return blank...the case statement should return (the then part and the else part) the same datatype or at least can be converted to the same datatype.

try ...else sum(0) end as A, ...or ....else 0 end as A

Error converting data type varchar to numeric.

Server: Msg 8114, Level 16, State 5
Error converting data type varchar to numeric.

Hello...
I new in MS SQL.
Given: 2 servers, same SQL statements, same input, same tables, same data types, same triggers.
Problem: One server works fine while the other returns the error above.

I have no idea of the problem why the other is working.IN addition to that, they also have the same MS SQL version.|||Perhaps you could post the relevant code, as well as the table structure? It would be quite impossible to help without these two crucial pieces of information.

Error converting data type varchar to numeric.

Hello,
I cannot get the following Insert Command work. I get the error:
Error converting data type varchar to numeric.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Error converting
data type varchar to numeric.
However 'rate' and 'maximum' variables are declared as Decimal
Dim rate As Decimal
Dim maximumAs Decimal
SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
RadioButtonList1.SelectedValue & "')"
SqlDataSource1.Insert()
CREATE TABLE Example(
userName nvarchar(50),
rate decimal(2, 2),
maximum decimal(6, 2),
ticket nchar(1)
)Try dropping the string delimiters (single quotes). Something like;
"INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
RadioButtonList1.SelectedValue & "')"
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hello,
|
| I cannot get the following Insert Command work. I get the error:
|
|
| Error converting data type varchar to numeric.
| Description: An unhandled exception occurred during the execution of
| the current web request. Please review the stack trace for more
| information about the error and where it originated in the code.
|
|
| Exception Details: System.Data.SqlClient.SqlException: Error converting
|
| data type varchar to numeric.
|
|
| However 'rate' and 'maximum' variables are declared as Decimal
|
|
| Dim rate As Decimal
| Dim maximumAs Decimal
|
|
| SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
| maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
| RadioButtonList1.SelectedValue & "')"
|
|
| SqlDataSource1.Insert()
|
|
| CREATE TABLE Example(
| userName nvarchar(50),
| rate decimal(2, 2),
| maximum decimal(6, 2),
| ticket nchar(1)
| )
||||Hi,
Already tried that. But this time I got the error:
There are fewer columns in the INSERT statement than values specified
in the VALUES clause. The number of values in the VALUES clause must
match the number of columns specified in the INSERT statement.
Dave Patrick wrote:
> Try dropping the string delimiters (single quotes). Something like;
> "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
> RadioButtonList1.SelectedValue & "')"
> --
> Regards,
> Dave Patrick ...Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
> "Dot Net Daddy" wrote:
> | Hello,
> |
> | I cannot get the following Insert Command work. I get the error:
> |
> |
> | Error converting data type varchar to numeric.
> | Description: An unhandled exception occurred during the execution of
> | the current web request. Please review the stack trace for more
> | information about the error and where it originated in the code.
> |
> |
> | Exception Details: System.Data.SqlClient.SqlException: Error converting
> |
> | data type varchar to numeric.
> |
> |
> | However 'rate' and 'maximum' variables are declared as Decimal
> |
> |
> | Dim rate As Decimal
> | Dim maximumAs Decimal
> |
> |
> | SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> | maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> | RadioButtonList1.SelectedValue & "')"
> |
> |
> | SqlDataSource1.Insert()
> |
> |
> | CREATE TABLE Example(
> | userName nvarchar(50),
> | rate decimal(2, 2),
> | maximum decimal(6, 2),
> | ticket nchar(1)
> | )
> ||||I'm not dotnet savvy but you might try something to the effect of;
MsgBox SqlDataSource1.InsertCommand
to see the actual SQL being passed.
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hi,
|
| Already tried that. But this time I got the error:
|
| There are fewer columns in the INSERT statement than values specified
| in the VALUES clause. The number of values in the VALUES clause must
| match the number of columns specified in the INSERT statement.|||thank you so much.. that helped..
silly me.. I was passing the logon name to the database, which was
causing the problem..
thanks for your help...
Dot Net Daddy wrote:
> Hi,
> Already tried that. But this time I got the error:
> There are fewer columns in the INSERT statement than values specified
> in the VALUES clause. The number of values in the VALUES clause must
> match the number of columns specified in the INSERT statement.
>
>
> Dave Patrick wrote:
> > Try dropping the string delimiters (single quotes). Something like;
> >
> > "INSERT INTO Example(userName, rate,
> > maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
> > RadioButtonList1.SelectedValue & "')"
> >
> > --
> >
> > Regards,
> >
> > Dave Patrick ...Please no email replies - reply in newsgroup.
> > Microsoft Certified Professional
> > Microsoft MVP [Windows]
> > http://www.microsoft.com/protect
> >
> > "Dot Net Daddy" wrote:
> > | Hello,
> > |
> > | I cannot get the following Insert Command work. I get the error:
> > |
> > |
> > | Error converting data type varchar to numeric.
> > | Description: An unhandled exception occurred during the execution of
> > | the current web request. Please review the stack trace for more
> > | information about the error and where it originated in the code.
> > |
> > |
> > | Exception Details: System.Data.SqlClient.SqlException: Error converting
> > |
> > | data type varchar to numeric.
> > |
> > |
> > | However 'rate' and 'maximum' variables are declared as Decimal
> > |
> > |
> > | Dim rate As Decimal
> > | Dim maximumAs Decimal
> > |
> > |
> > | SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> > | maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> > | RadioButtonList1.SelectedValue & "')"
> > |
> > |
> > | SqlDataSource1.Insert()
> > |
> > |
> > | CREATE TABLE Example(
> > | userName nvarchar(50),
> > | rate decimal(2, 2),
> > | maximum decimal(6, 2),
> > | ticket nchar(1)
> > | )
> > ||||Good to hear. You're welcome.
--
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| thank you so much.. that helped..
|
| silly me.. I was passing the logon name to the database, which was
| causing the problem..
|
| thanks for your help...|||I see you have found a resolution to your immediate problem but I want to
point out that this code has a serious vulnerability to SQL injection. I
strongly recommend that you use command parameters instead of string
concatenation and perhaps also use only stored procedures so that direct
table permissions are not needed.
Google "SQL injection" find many discussions on the topic.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Dot Net Daddy" <cagriandac@.gmail.com> wrote in message
news:1156041975.673742.64030@.h48g2000cwc.googlegroups.com...
> Hello,
> I cannot get the following Insert Command work. I get the error:
>
> Error converting data type varchar to numeric.
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.Data.SqlClient.SqlException: Error converting
> data type varchar to numeric.
>
> However 'rate' and 'maximum' variables are declared as Decimal
>
> Dim rate As Decimal
> Dim maximumAs Decimal
>
> SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> RadioButtonList1.SelectedValue & "')"
>
> SqlDataSource1.Insert()
>
> CREATE TABLE Example(
> userName nvarchar(50),
> rate decimal(2, 2),
> maximum decimal(6, 2),
> ticket nchar(1)
> )
>

Error converting data type varchar to numeric.

Hello,
I cannot get the following Insert Command work. I get the error:
Error converting data type varchar to numeric.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Error converting
data type varchar to numeric.
However 'rate' and 'maximum' variables are declared as Decimal
Dim rate As Decimal
Dim maximumAs Decimal
SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
RadioButtonList1.SelectedValue & "')"
SqlDataSource1.Insert()
CREATE TABLE Example(
userName nvarchar(50),
rate decimal(2, 2),
maximum decimal(6, 2),
ticket nchar(1)
)Try dropping the string delimiters (single quotes). Something like;
"INSERT INTO Example(userName, rate,
maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
RadioButtonList1.SelectedValue & "')"
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hello,
|
| I cannot get the following Insert Command work. I get the error:
|
|
| Error converting data type varchar to numeric.
| Description: An unhandled exception occurred during the execution of
| the current web request. Please review the stack trace for more
| information about the error and where it originated in the code.
|
|
| Exception Details: System.Data.SqlClient.SqlException: Error converting
|
| data type varchar to numeric.
|
|
| However 'rate' and 'maximum' variables are declared as Decimal
|
|
| Dim rate As Decimal
| Dim maximumAs Decimal
|
|
| SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
| maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
| RadioButtonList1.SelectedValue & "')"
|
|
| SqlDataSource1.Insert()
|
|
| CREATE TABLE Example(
| userName nvarchar(50),
| rate decimal(2, 2),
| maximum decimal(6, 2),
| ticket nchar(1)
| )
||||Hi,
Already tried that. But this time I got the error:
There are fewer columns in the INSERT statement than values specified
in the VALUES clause. The number of values in the VALUES clause must
match the number of columns specified in the INSERT statement.
Dave Patrick wrote:
> Try dropping the string delimiters (single quotes). Something like;
> "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla'," & rate & "," & maximum & ",'" &
> RadioButtonList1.SelectedValue & "')"
> --
> Regards,
> Dave Patrick ...Please no email replies - reply in newsgroup.
> Microsoft Certified Professional
> Microsoft MVP [Windows]
> http://www.microsoft.com/protect
> "Dot Net Daddy" wrote:
> | Hello,
> |
> | I cannot get the following Insert Command work. I get the error:
> |
> |
> | Error converting data type varchar to numeric.
> | Description: An unhandled exception occurred during the execution of
> | the current web request. Please review the stack trace for more
> | information about the error and where it originated in the code.
> |
> |
> | Exception Details: System.Data.SqlClient.SqlException: Error converting
> |
> | data type varchar to numeric.
> |
> |
> | However 'rate' and 'maximum' variables are declared as Decimal
> |
> |
> | Dim rate As Decimal
> | Dim maximumAs Decimal
> |
> |
> | SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> | maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> | RadioButtonList1.SelectedValue & "')"
> |
> |
> | SqlDataSource1.Insert()
> |
> |
> | CREATE TABLE Example(
> | userName nvarchar(50),
> | rate decimal(2, 2),
> | maximum decimal(6, 2),
> | ticket nchar(1)
> | )
> ||||I'm not dotnet savvy but you might try something to the effect of;
MsgBox SqlDataSource1.InsertCommand
to see the actual SQL being passed.
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| Hi,
|
| Already tried that. But this time I got the error:
|
| There are fewer columns in the INSERT statement than values specified
| in the VALUES clause. The number of values in the VALUES clause must
| match the number of columns specified in the INSERT statement.|||thank you so much.. that helped..
silly me.. I was passing the logon name to the database, which was
causing the problem..
thanks for your help...
Dot Net Daddy wrote:[vbcol=seagreen]
> Hi,
> Already tried that. But this time I got the error:
> There are fewer columns in the INSERT statement than values specified
> in the VALUES clause. The number of values in the VALUES clause must
> match the number of columns specified in the INSERT statement.
>
>
> Dave Patrick wrote:|||Good to hear. You're welcome.
Regards,
Dave Patrick ...Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
"Dot Net Daddy" wrote:
| thank you so much.. that helped..
|
| silly me.. I was passing the logon name to the database, which was
| causing the problem..
|
| thanks for your help...|||I see you have found a resolution to your immediate problem but I want to
point out that this code has a serious vulnerability to SQL injection. I
strongly recommend that you use command parameters instead of string
concatenation and perhaps also use only stored procedures so that direct
table permissions are not needed.
Google "SQL injection" find many discussions on the topic.
Hope this helps.
Dan Guzman
SQL Server MVP
"Dot Net Daddy" <cagriandac@.gmail.com> wrote in message
news:1156041975.673742.64030@.h48g2000cwc.googlegroups.com...
> Hello,
> I cannot get the following Insert Command work. I get the error:
>
> Error converting data type varchar to numeric.
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
>
> Exception Details: System.Data.SqlClient.SqlException: Error converting
> data type varchar to numeric.
>
> However 'rate' and 'maximum' variables are declared as Decimal
>
> Dim rate As Decimal
> Dim maximumAs Decimal
>
> SqlDataSource1.InsertCommand = "INSERT INTO Example(userName, rate,
> maximum, ticket) VALUES('blabla','" & rate & "','" & maximum & "','" &
> RadioButtonList1.SelectedValue & "')"
>
> SqlDataSource1.Insert()
>
> CREATE TABLE Example(
> userName nvarchar(50),
> rate decimal(2, 2),
> maximum decimal(6, 2),
> ticket nchar(1)
> )
>

Error converting data type varchar to numeric.

Excuse me for my english.
Let us start with the base. I work with SQLServer 2000. My table has 12
columns of the type varchar Ex.:(Condition1_Min, Condition1_Max,
Condition2_Min, Condition2_Max etc...)
There are values which must be interpreted like the numerical one and of
other as alpha. Here a request which does not function in Query Analyser
It seems that if I cast my condition1_min, for example, as soon as I have a
request which still uses condition1_min but not cast then sql server this
error message gives me.
Here an example of request:
SELECT
NO_MACHINE,NOM_PROCEDURE,CONDITION1_MIN,
CONDITION1_MAX,CONDITION1_TOUS,CONDI
TION2_MIN,CONDITION2_MAX,CONDITION2_TOUS
,CONDITION3_MIN,CONDITION3_MAX,CONDI
TION3_TOUS,CONDITION4_MIN,CONDITION4_MAX
,CONDITION4_TOUS,CONDITION5_MIN,COND
ITION5_MAX,CONDITION5_TOUS,
CONDITION6_MIN,CONDITION6_MAX,CONDITION6
_TOUS,NO_GRP_INSTRUCTIONS,RAZ_BORNE
FROM MES_PROCEDURECONDITIONS
WHERE (NO_MACHINE = '00300') AND (CONDITION1_MIN >= 'AK' AND CONDITION1_MAX
<= 'AK') AND (CONDITION2_MIN >= '4' AND CONDITION2_MAX <= '4') AND
NOM_PROCEDURE = 'ChangRouleaux' OR (NO_MACHINE = '00300') AND
(CONDITION1_MIN >= '2' AND CONDITION1_MAX <= '2') AND (CONDITION2_MIN >= '4
'
AND CONDITION2_MAX <= '4') AND NOM_PROCEDURE = 'Insp. Feuille Début' OR
(NO_MACHINE = '00300') AND (CONDITION1_MIN >= 'False' AND CONDITION1_MAX <=
'False') AND (cast(CONDITION2_MIN as decimal) >= 0.065 AND
cast(CONDITION2_MAX as decimal) <= 0.065) AND (CONDITION3_MIN >= '4' AND
CONDITION3_MAX <= '4') AND (CONDITION4_MIN >= '2' AND CONDITION4_MAX <= '2'
)
AND NOM_PROCEDURE = 'Inspection Final' OR (NO_MACHINE = '00300') AND
(CONDITION1_MIN >= 'LR' AND CONDITION1_MAX <= 'LR') AND (CONDITION2_MIN >=
'2' AND CONDITION2_MAX <= '2') AND (CONDITION3_MIN >= '4' AND CONDITION3_MA
X
<= '4') AND (CONDITION4_MIN >= '0' AND CONDITION4_MAX <= '0') AND
NOM_PROCEDURE = 'Largeur 1 re bob équ' OR (NO_MACHINE = '00300') AND
(CONDITION1_MIN >= 'False' AND CONDITION1_MAX <= 'False') AND
(CONDITION2_MIN >= 'LR' AND CONDITION2_MAX <= 'LR') AND (CONDITION3_MIN >=
'0' AND CONDITION3_MAX <= '0') AND (CONDITION4_MIN >= '4' AND CONDITION4_MA
X
<= '4') AND NOM_PROCEDURE = 'Largeur Final 1er bob' OR (NO_MACHINE =
'00300') AND (CONDITION1_MIN >= 'AK' AND CONDITION1_MAX <= 'AK') AND
(CONDITION2_MIN >= 'LR' AND CONDITION2_MAX <= 'LR') AND (CONDITION3_MIN >=
'0' AND CONDITION3_MAX <= '0') AND (CONDITION4_MIN >= '4' AND CONDITION4_MA
X
<= '4') AND NOM_PROCEDURE = 'Largeur Foil 1re bobi.' OR (NO_MACHINE =
'00300') AND (CONDITION1_MIN >= 'LR' AND CONDITION1_MAX <= 'LR') AND
(CONDITION2_MIN >= '4' AND CONDITION2_MAX <= '4') AND NOM_PROCEDURE =
'Largeur_PI' OR (NO_MACHINE = '00300') AND (CONDITION1_MIN >= '145418001'
AND CONDITION1_MAX <= '145418001') AND (CONDITION2_MIN >= '2' AND
CONDITION2_MAX <= '2') AND (CONDITION3_MIN >= '875' AND CONDITION3_MAX <=
'875') AND (CONDITION4_MIN >= '4' AND CONDITION4_MAX <= '4') AND
NOM_PROCEDURE = 'Lavage' OR (NO_MACHINE = '00300') AND (CONDITION1_MIN <=
'False' AND CONDITION1_MAX >= 'False') AND (cast(CONDITION2_MIN as decimal)
>= 0.065 AND cast(CONDITION2_MAX as decimal(38,10)) <= 0.065) AND
(CONDITION3_MIN >= '4' AND CONDITION3_MAX <= '4') AND NOM_PROCEDURE =
'Standardi. Final 1er b' OR (NO_MACHINE = '00300') AND (cast(CONDITION1_MI
N
as decimal(38,10)) >= 0.065 AND cast(CONDITION1_MAX as decimal) <= 0.065) AN
D
(CONDITION2_MIN >= '2' AND CONDITION2_MAX <= '2') AND (CONDITION3_MIN >=
'4' AND CONDITION3_MAX <= '4') AND NOM_PROCEDURE = 'Standardisation Déb.'
ORDER BY NO_MACHINE,NOM_PROCEDURE
Under condition min and max I can have alphas and num data. The request is
made with generic program. I need your ideas.
Thank you for your assistance!!!Hi
Posting DDL and example data as described in
http://www.aspfaq.com/etiquett___e.asp?id=5006 helps when answering quest
ions
like this.
CONDITION2_MIN >= '4' AND CONDITION2_MAX <= '4'
is not the same as
CONDITION2_MIN >= 4 AND CONDITION2_MAX <= 4
e.g.
SELECT * FROM
( SELECT '10' as [Min], '20' AS [MAX]
UNION ALL SELECT '4', '8' ) A
WHERE [Min] >= '4'
SELECT * FROM
( SELECT '10' as [Min], '20' AS [MAX]
UNION ALL SELECT '4', '8' ) A
WHERE [Min] >= 4
And it would seem more logical if the condition was
CONDITION2_MIN <= 4 AND CONDITION2_MAX >= 4
If you are having conversion errors using PATINDEX or ISNUMERIC may help.
John
"Ric" wrote:

> Excuse me for my english.
> Let us start with the base. I work with SQLServer 2000. My table has 12
> columns of the type varchar Ex.:(Condition1_Min, Condition1_Max,
> Condition2_Min, Condition2_Max etc...)
> There are values which must be interpreted like the numerical one and of
> other as alpha. Here a request which does not function in Query Analyser
> It seems that if I cast my condition1_min, for example, as soon as I have
a
> request which still uses condition1_min but not cast then sql server this
> error message gives me.
> Here an example of request:
> SELECT
> NO_MACHINE,NOM_PROCEDURE,CONDITION1_MIN,
CONDITION1_MAX,CONDITION1_TOUS,CONDITION
2_
MIN,CONDITION2_MAX,CONDITION2_TOUS,CONDI
TION3_MIN,CONDITION3_MAX,CONDITION3_TOUS
,CON
DITION4_MIN,CONDITION4_MAX,CONDITION4_TO
US,CONDITION5_MIN,CONDITION5_MAX,CONDITI
ON5_
TOU
S,CONDITION6_MIN,CONDITION6_MAX,CONDITIO
N6_TOUS,NO_GRP_INSTRUCTIONS,RAZ_BORNE[co
lor=darkred
]
> FROM MES_PROCEDURECONDITIONS
> WHERE (NO_MACHINE = '00300') AND (CONDITION1_MIN >= 'AK' AND CONDITION1_MA
X
> <= 'AK') AND (CONDITION2_MIN >= '4' AND CONDITION2_MAX <= '4') AND
> NOM_PROCEDURE = 'ChangRouleaux' OR (NO_MACHINE = '00300') AND
> (CONDITION1_MIN >= '2' AND CONDITION1_MAX <= '2') AND (CONDITION2_MIN >=
'4'
> AND CONDITION2_MAX <= '4') AND NOM_PROCEDURE = 'Insp. Feuille Début' OR
> (NO_MACHINE = '00300') AND (CONDITION1_MIN >= 'False' AND CONDITION1_MAX
<=
> 'False') AND (cast(CONDITION2_MIN as decimal) >= 0.065 AND
> cast(CONDITION2_MAX as decimal) <= 0.065) AND (CONDITION3_MIN >= '4' AND
> CONDITION3_MAX <= '4') AND (CONDITION4_MIN >= '2' AND CONDITION4_MAX <= '
2')
> AND NOM_PROCEDURE = 'Inspection Final' OR (NO_MACHINE = '00300') AND
> (CONDITION1_MIN >= 'LR' AND CONDITION1_MAX <= 'LR') AND (CONDITION2_MIN >
=
> '2' AND CONDITION2_MAX <= '2') AND (CONDITION3_MIN >= '4' AND CONDITION3_
MAX
> <= '4') AND (CONDITION4_MIN >= '0' AND CONDITION4_MAX <= '0') AND
> NOM_PROCEDURE = 'Largeur 1 re bob équ' OR (NO_MACHINE = '00300') AND
> (CONDITION1_MIN >= 'False' AND CONDITION1_MAX <= 'False') AND
> (CONDITION2_MIN >= 'LR' AND CONDITION2_MAX <= 'LR') AND (CONDITION3_MIN >
=
> '0' AND CONDITION3_MAX <= '0') AND (CONDITION4_MIN >= '4' AND CONDITION4_
MAX
> <= '4') AND NOM_PROCEDURE = 'Largeur Final 1er bob' OR (NO_MACHINE =
> '00300') AND (CONDITION1_MIN >= 'AK' AND CONDITION1_MAX <= 'AK') AND
> (CONDITION2_MIN >= 'LR' AND CONDITION2_MAX <= 'LR') AND (CONDITION3_MIN >
=
> '0' AND CONDITION3_MAX <= '0') AND (CONDITION4_MIN >= '4' AND CONDITION4_
MAX
> <= '4') AND NOM_PROCEDURE = 'Largeur Foil 1re bobi.' OR (NO_MACHINE =
> '00300') AND (CONDITION1_MIN >= 'LR' AND CONDITION1_MAX <= 'LR') AND
> (CONDITION2_MIN >= '4' AND CONDITION2_MAX <= '4') AND NOM_PROCEDURE =
> 'Largeur_PI' OR (NO_MACHINE = '00300') AND (CONDITION1_MIN >= '145418001
'
> AND CONDITION1_MAX <= '145418001') AND (CONDITION2_MIN >= '2' AND
> CONDITION2_MAX <= '2') AND (CONDITION3_MIN >= '875' AND CONDITION3_MAX <=
> '875') AND (CONDITION4_MIN >= '4' AND CONDITION4_MAX <= '4') AND
> NOM_PROCEDURE = 'Lavage' OR (NO_MACHINE = '00300') AND (CONDITION1_MIN <
=
> 'False' AND CONDITION1_MAX >= 'False') AND (cast(CONDITION2_MIN as decima
l)
> (CONDITION3_MIN >= '4' AND CONDITION3_MAX <= '4') AND NOM_PROCEDURE =
> 'Standardi. Final 1er b' OR (NO_MACHINE = '00300') AND (cast(CONDITION1_
MIN
> as decimal(38,10)) >= 0.065 AND cast(CONDITION1_MAX as decimal) <= 0.065)
AND
> (CONDITION2_MIN >= '2' AND CONDITION2_MAX <= '2') AND (CONDITION3_MIN >=
> '4' AND CONDITION3_MAX <= '4') AND NOM_PROCEDURE = 'Standardisation Déb.'
> ORDER BY NO_MACHINE,NOM_PROCEDURE
> Under condition min and max I can have alphas and num data. The request is
> made with generic program. I need your ideas.
> Thank you for your assistance!!!
>[/color]

Error converting data type varchar to numeric

Hi,

Thank you in advance for your comments/suggestions. I am trying to create a View of a Table. The table is created by another application so I am unable to recreate it they way I want, also the data that is in the columns that I want to CAST are "numbers" not letters and will only be numbers. In the view I need certain columns to be CAST as numeric from varchar.

Here is the syntax that I am currently using:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time], szF2 AS [User Name], CAST(szF3 AS numeric) AS [Documents Indexed], CAST(szF4 AS datetime) AS [Logout Date/Time], CAST(szF5 AS numeric) AS [Documents Sent to QC], CAST(szF6 AS numeric) AS [Documents Reconciled], szF7 AS [Reject Reason], CAST(szF8 AS datetime) AS [Report Date]

FROM dbo.F_Report_Data AS a

WHERE (szF3 <> 'Blank')

When I open the view I get the error message about converting varchar to numeric.

Thanks,

Erik

Try running this query:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time],
szF2 AS [User Name],
-- CAST(szF3 AS numeric) AS [Documents Indexed],
szF3,
CAST(szF4 AS datetime) AS [Logout Date/Time],
-- CAST(szF5 AS numeric) AS [Documents Sent to QC],
-- CAST(szF6 AS numeric) AS [Documents Reconciled],
szF5,
szF6,
szF7 AS [Reject Reason],
CAST(szF8 AS datetime) AS [Report Date]
FROM dbo.F_Report_Data AS a
where isNumeric (szF3 + 'D0') = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0

And post any results that get returned.|||

I tried your suggestion and I got an error: "Error in list of function arguments: '=' not recognized. Unable to parse query text.

|||

It's likely because you have data in the szF5 or szF6 columns that can't be converted to numeric. For example, if I had the value aaa in szF5, I would get that error. More common is if I have a zero length string in the column, that can't be converted to numeric and I would get the error. A null would be fine but a zero length string would cause the error.

-Sue

|||

I would suggest (1) give the schema of the table and (2) give 5 sample rows of data from the table by doing a

select top 5 * from F_Report_Data

|||

The 3 columns that I want to cast as numeric have only numbers in them.

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

|||

The 3 columns that I want to cast as numeric have only numbers in them.

Code Snippet

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

Could you clarify by what you mean "Schema", it has been a while since my DB class and I am not a DBA. Every column is varchar(8000),null except for the PK which is (int, not null).

I awm giong to attempt to see if I can get the necessary results w/o convert/cast because there is supposed to be implicit conversion of varchar to numeric.

|||

Actually, you have answered the schema question -- all columns are varchar(8000) except for the PK which is integer -- a "wow" table. That should be enough for now. Try running this query and see if any results are returned:

Code Snippet

select left(szF1, 25) as szF1,
left(szF2, 25) as szF2,
left(szF3, 25) as szF3,
left(szF4, 25) as szF4,
left(szF5, 25) as szF5,
left(szF6, 25) as szF6,
left(szF7, 25) as szF7,
left(szF8, 25) as szF8
from dbo.F_Report_data
where isDate(szF1) = 0
or isNumeric (szF3 + 'D0') = 0
or isDate(szF4) = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0
or isDate(szF8) = 0

|||

Yes it returned a result, it's good that it returned a result but does that mean that we can/cannot convert/cast a varchar as a numeric? Thanks for your help!!

|||

Please post a sampling of the results that you received. It means that you will might either need to change the table or modify the way you display the data so that it is properly "clensed" -- you have dirty data.

|||

Here are the results:

Code Snippet

01/24/2007 09:58:03 AM admin 207 01/24/2007 02:08:55 PM 0 0 20070124
01/24/2007 09:59:03 AM admin 0 01/24/2007 04:09:25 PM 1 0 Unable to read case numbe 20070124
01/24/2007 09:56:03 AM admin 0 01/24/2007 04:26:33 PM 0 3 20070124
01/25/2007 01:55:19 PM admin 3 01/25/2007 03:32:51 PM 0 0 20070125

01/25/2007 01:55:19 PM test 0 01/25/2007 04:11:09 PM 1 0 Unable to read case numbe 20070125

| szf1| |szF2| szF3 |--szF4-| szF5 sz F6 |-szF7-| |szF8|

I just noticed that the query trimmed szF7 (Where it says "Unable to read case numbe"), I will need that field a little larger for the text. I never would have thought that there would be so much trouble to convert/cast a varchar to a numeric in a view.|||That did not display the same way it did on my screen when I was typing it. I hope it isn't too confusing.|||

Can somebody point Erik to an article about cleaning up data? My tests weren't strong enough and I really am not interested in wasting Erik's time. I suspect that blanks in his data caused the isNumeric tests to fail.

Erik:

You can try this query; it will exhibit which test is failing:

Code Snippet

select isDate(rtrim(szF1)) as szF1isDate,
isNumeric (rtrim(szF3) + 'D0') as szF3IsNumeric,
isDate(rtrim(szF4)) as szF4IsDate,
isNumeric (rtrim(szF5) + 'D0') as szF5IsNumeric,
isNumeric (rtrim(szF6) + 'D0') as szF6IsNumeric,
isDate(rtrim(szF8)) as szF8isDate,
left(szF1, 30) as szF1,
left(szF2, 30) as szF2,
left(szF3, 30) as szF3,
left(szF4, 30) as szF4,
left(szF5, 30) as szF5,
left(szF6, 30) as szF6,
left(szF7, 30) as szF7,
left(szF8, 30) as szF8
from dbo.F_Report_data
where isDate(rtrim(szF1)) = 0
or isNumeric (rtrim(szF3) + 'D0') = 0
or isDate(rtrim(szF4)) = 0
or isNumeric (rtrim(szF5) + 'D0') = 0
or isNumeric (rtrim(szF6) + 'D0') = 0
or isDate(rtrim(szF8)) = 0

I feel like I need a fresh set of eyes on this at this point. Help?

|||

Here are the results of the query. I don't really know what they are saying though, could you give me pseudo code explanation of the query?

0,1,0,1,1,0,,Blank,0,,0,0,,
1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518

|||

Erik:

To me the problem here is that the columns are not sufficiently typed; this is a design problem that should be fixed. If a column is intended to be used as a number it should be typed as numeric. Similarly, if a column is going to be used as a date it should be typed as a datetime column, not as a varchar. Here is the basic response to the records returned from the query:

0,1,0,1,1,0,,Blank,0,,0,0,,
this record failed for 3 reasons:
(1) The szF1 field is not a valid date (it is an empty string)
(2) The szF4 field is not a valid date (it is an empty string)
(3) the szF8 field is not a valid date (it is an empty string)

1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
this record faild for two reasons:
(1) The szF5 field is not numeric (it is an empty string)
(2) the szF6 field is not numeric (it is an empty string)

]

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

Now, you might be able to use the NULLIF function to get around these problems since all of these are manifest when the column is an EMPTY string. If you are wanting to test for NUMERIC columns you might also want to give a look to this article about problems with the "isNumeric" built-in function:

http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Error converting data type varchar to numeric

Hi,

Thank you in advance for your comments/suggestions. I am trying to create a View of a Table. The table is created by another application so I am unable to recreate it they way I want, also the data that is in the columns that I want to CAST are "numbers" not letters and will only be numbers. In the view I need certain columns to be CAST as numeric from varchar.

Here is the syntax that I am currently using:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time], szF2 AS [User Name], CAST(szF3 AS numeric) AS [Documents Indexed], CAST(szF4 AS datetime) AS [Logout Date/Time], CAST(szF5 AS numeric) AS [Documents Sent to QC], CAST(szF6 AS numeric) AS [Documents Reconciled], szF7 AS [Reject Reason], CAST(szF8 AS datetime) AS [Report Date]

FROM dbo.F_Report_Data AS a

WHERE (szF3 <> 'Blank')

When I open the view I get the error message about converting varchar to numeric.

Thanks,

Erik

Try running this query:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time],
szF2 AS [User Name],
-- CAST(szF3 AS numeric) AS [Documents Indexed],
szF3,
CAST(szF4 AS datetime) AS [Logout Date/Time],
-- CAST(szF5 AS numeric) AS [Documents Sent to QC],
-- CAST(szF6 AS numeric) AS [Documents Reconciled],
szF5,
szF6,
szF7 AS [Reject Reason],
CAST(szF8 AS datetime) AS [Report Date]
FROM dbo.F_Report_Data AS a
where isNumeric (szF3 + 'D0') = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0

And post any results that get returned.|||

I tried your suggestion and I got an error: "Error in list of function arguments: '=' not recognized. Unable to parse query text.

|||

It's likely because you have data in the szF5 or szF6 columns that can't be converted to numeric. For example, if I had the value aaa in szF5, I would get that error. More common is if I have a zero length string in the column, that can't be converted to numeric and I would get the error. A null would be fine but a zero length string would cause the error.

-Sue

|||

I would suggest (1) give the schema of the table and (2) give 5 sample rows of data from the table by doing a

select top 5 * from F_Report_Data

|||

The 3 columns that I want to cast as numeric have only numbers in them.

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

|||

The 3 columns that I want to cast as numeric have only numbers in them.

Code Snippet

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

Could you clarify by what you mean "Schema", it has been a while since my DB class and I am not a DBA. Every column is varchar(8000),null except for the PK which is (int, not null).

I awm giong to attempt to see if I can get the necessary results w/o convert/cast because there is supposed to be implicit conversion of varchar to numeric.

|||

Actually, you have answered the schema question -- all columns are varchar(8000) except for the PK which is integer -- a "wow" table. That should be enough for now. Try running this query and see if any results are returned:

Code Snippet

select left(szF1, 25) as szF1,
left(szF2, 25) as szF2,
left(szF3, 25) as szF3,
left(szF4, 25) as szF4,
left(szF5, 25) as szF5,
left(szF6, 25) as szF6,
left(szF7, 25) as szF7,
left(szF8, 25) as szF8
from dbo.F_Report_data
where isDate(szF1) = 0
or isNumeric (szF3 + 'D0') = 0
or isDate(szF4) = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0
or isDate(szF8) = 0

|||

Yes it returned a result, it's good that it returned a result but does that mean that we can/cannot convert/cast a varchar as a numeric? Thanks for your help!!

|||

Please post a sampling of the results that you received. It means that you will might either need to change the table or modify the way you display the data so that it is properly "clensed" -- you have dirty data.

|||

Here are the results:

Code Snippet

01/24/2007 09:58:03 AM admin 207 01/24/2007 02:08:55 PM 0 0 20070124
01/24/2007 09:59:03 AM admin 0 01/24/2007 04:09:25 PM 1 0 Unable to read case numbe 20070124
01/24/2007 09:56:03 AM admin 0 01/24/2007 04:26:33 PM 0 3 20070124
01/25/2007 01:55:19 PM admin 3 01/25/2007 03:32:51 PM 0 0 20070125

01/25/2007 01:55:19 PM test 0 01/25/2007 04:11:09 PM 1 0 Unable to read case numbe 20070125

| szf1| |szF2| szF3 |--szF4-| szF5 sz F6 |-szF7-| |szF8|

I just noticed that the query trimmed szF7 (Where it says "Unable to read case numbe"), I will need that field a little larger for the text. I never would have thought that there would be so much trouble to convert/cast a varchar to a numeric in a view.|||That did not display the same way it did on my screen when I was typing it. I hope it isn't too confusing.|||

Can somebody point Erik to an article about cleaning up data? My tests weren't strong enough and I really am not interested in wasting Erik's time. I suspect that blanks in his data caused the isNumeric tests to fail.

Erik:

You can try this query; it will exhibit which test is failing:

Code Snippet

select isDate(rtrim(szF1)) as szF1isDate,
isNumeric (rtrim(szF3) + 'D0') as szF3IsNumeric,
isDate(rtrim(szF4)) as szF4IsDate,
isNumeric (rtrim(szF5) + 'D0') as szF5IsNumeric,
isNumeric (rtrim(szF6) + 'D0') as szF6IsNumeric,
isDate(rtrim(szF8)) as szF8isDate,
left(szF1, 30) as szF1,
left(szF2, 30) as szF2,
left(szF3, 30) as szF3,
left(szF4, 30) as szF4,
left(szF5, 30) as szF5,
left(szF6, 30) as szF6,
left(szF7, 30) as szF7,
left(szF8, 30) as szF8
from dbo.F_Report_data
where isDate(rtrim(szF1)) = 0
or isNumeric (rtrim(szF3) + 'D0') = 0
or isDate(rtrim(szF4)) = 0
or isNumeric (rtrim(szF5) + 'D0') = 0
or isNumeric (rtrim(szF6) + 'D0') = 0
or isDate(rtrim(szF8)) = 0

I feel like I need a fresh set of eyes on this at this point. Help?

|||

Here are the results of the query. I don't really know what they are saying though, could you give me pseudo code explanation of the query?

0,1,0,1,1,0,,Blank,0,,0,0,,
1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518

|||

Erik:

To me the problem here is that the columns are not sufficiently typed; this is a design problem that should be fixed. If a column is intended to be used as a number it should be typed as numeric. Similarly, if a column is going to be used as a date it should be typed as a datetime column, not as a varchar. Here is the basic response to the records returned from the query:

0,1,0,1,1,0,,Blank,0,,0,0,,
this record failed for 3 reasons:
(1) The szF1 field is not a valid date (it is an empty string)
(2) The szF4 field is not a valid date (it is an empty string)
(3) the szF8 field is not a valid date (it is an empty string)

1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
this record faild for two reasons:
(1) The szF5 field is not numeric (it is an empty string)
(2) the szF6 field is not numeric (it is an empty string)

]

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

Now, you might be able to use the NULLIF function to get around these problems since all of these are manifest when the column is an EMPTY string. If you are wanting to test for NUMERIC columns you might also want to give a look to this article about problems with the "isNumeric" built-in function:

http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Error converting data type varchar to numeric

Hi,

Thank you in advance for your comments/suggestions. I am trying to create a View of a Table. The table is created by another application so I am unable to recreate it they way I want, also the data that is in the columns that I want to CAST are "numbers" not letters and will only be numbers. In the view I need certain columns to be CAST as numeric from varchar.

Here is the syntax that I am currently using:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time], szF2 AS [User Name], CAST(szF3 AS numeric) AS [Documents Indexed], CAST(szF4 AS datetime) AS [Logout Date/Time], CAST(szF5 AS numeric) AS [Documents Sent to QC], CAST(szF6 AS numeric) AS [Documents Reconciled], szF7 AS [Reject Reason], CAST(szF8 AS datetime) AS [Report Date]

FROM dbo.F_Report_Data AS a

WHERE (szF3 <> 'Blank')

When I open the view I get the error message about converting varchar to numeric.

Thanks,

Erik

Try running this query:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time],
szF2 AS [User Name],
-- CAST(szF3 AS numeric) AS [Documents Indexed],
szF3,
CAST(szF4 AS datetime) AS [Logout Date/Time],
-- CAST(szF5 AS numeric) AS [Documents Sent to QC],
-- CAST(szF6 AS numeric) AS [Documents Reconciled],
szF5,
szF6,
szF7 AS [Reject Reason],
CAST(szF8 AS datetime) AS [Report Date]
FROM dbo.F_Report_Data AS a
where isNumeric (szF3 + 'D0') = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0

And post any results that get returned.|||

I tried your suggestion and I got an error: "Error in list of function arguments: '=' not recognized. Unable to parse query text.

|||

It's likely because you have data in the szF5 or szF6 columns that can't be converted to numeric. For example, if I had the value aaa in szF5, I would get that error. More common is if I have a zero length string in the column, that can't be converted to numeric and I would get the error. A null would be fine but a zero length string would cause the error.

-Sue

|||

I would suggest (1) give the schema of the table and (2) give 5 sample rows of data from the table by doing a

select top 5 * from F_Report_Data

|||

The 3 columns that I want to cast as numeric have only numbers in them.

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

|||

The 3 columns that I want to cast as numeric have only numbers in them.

Code Snippet

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

Could you clarify by what you mean "Schema", it has been a while since my DB class and I am not a DBA. Every column is varchar(8000),null except for the PK which is (int, not null).

I awm giong to attempt to see if I can get the necessary results w/o convert/cast because there is supposed to be implicit conversion of varchar to numeric.

|||

Actually, you have answered the schema question -- all columns are varchar(8000) except for the PK which is integer -- a "wow" table. That should be enough for now. Try running this query and see if any results are returned:

Code Snippet

select left(szF1, 25) as szF1,
left(szF2, 25) as szF2,
left(szF3, 25) as szF3,
left(szF4, 25) as szF4,
left(szF5, 25) as szF5,
left(szF6, 25) as szF6,
left(szF7, 25) as szF7,
left(szF8, 25) as szF8
from dbo.F_Report_data
where isDate(szF1) = 0
or isNumeric (szF3 + 'D0') = 0
or isDate(szF4) = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0
or isDate(szF8) = 0

|||

Yes it returned a result, it's good that it returned a result but does that mean that we can/cannot convert/cast a varchar as a numeric? Thanks for your help!!

|||

Please post a sampling of the results that you received. It means that you will might either need to change the table or modify the way you display the data so that it is properly "clensed" -- you have dirty data.

|||

Here are the results:

Code Snippet

01/24/2007 09:58:03 AM admin 207 01/24/2007 02:08:55 PM 0 0 20070124
01/24/2007 09:59:03 AM admin 0 01/24/2007 04:09:25 PM 1 0 Unable to read case numbe 20070124
01/24/2007 09:56:03 AM admin 0 01/24/2007 04:26:33 PM 0 3 20070124
01/25/2007 01:55:19 PM admin 3 01/25/2007 03:32:51 PM 0 0 20070125

01/25/2007 01:55:19 PM test 0 01/25/2007 04:11:09 PM 1 0 Unable to read case numbe 20070125

| szf1| |szF2| szF3 |--szF4-| szF5 sz F6 |-szF7-| |szF8|

I just noticed that the query trimmed szF7 (Where it says "Unable to read case numbe"), I will need that field a little larger for the text. I never would have thought that there would be so much trouble to convert/cast a varchar to a numeric in a view.|||That did not display the same way it did on my screen when I was typing it. I hope it isn't too confusing.|||

Can somebody point Erik to an article about cleaning up data? My tests weren't strong enough and I really am not interested in wasting Erik's time. I suspect that blanks in his data caused the isNumeric tests to fail.

Erik:

You can try this query; it will exhibit which test is failing:

Code Snippet

select isDate(rtrim(szF1)) as szF1isDate,
isNumeric (rtrim(szF3) + 'D0') as szF3IsNumeric,
isDate(rtrim(szF4)) as szF4IsDate,
isNumeric (rtrim(szF5) + 'D0') as szF5IsNumeric,
isNumeric (rtrim(szF6) + 'D0') as szF6IsNumeric,
isDate(rtrim(szF8)) as szF8isDate,
left(szF1, 30) as szF1,
left(szF2, 30) as szF2,
left(szF3, 30) as szF3,
left(szF4, 30) as szF4,
left(szF5, 30) as szF5,
left(szF6, 30) as szF6,
left(szF7, 30) as szF7,
left(szF8, 30) as szF8
from dbo.F_Report_data
where isDate(rtrim(szF1)) = 0
or isNumeric (rtrim(szF3) + 'D0') = 0
or isDate(rtrim(szF4)) = 0
or isNumeric (rtrim(szF5) + 'D0') = 0
or isNumeric (rtrim(szF6) + 'D0') = 0
or isDate(rtrim(szF8)) = 0

I feel like I need a fresh set of eyes on this at this point. Help?

|||

Here are the results of the query. I don't really know what they are saying though, could you give me pseudo code explanation of the query?

0,1,0,1,1,0,,Blank,0,,0,0,,
1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518

|||

Erik:

To me the problem here is that the columns are not sufficiently typed; this is a design problem that should be fixed. If a column is intended to be used as a number it should be typed as numeric. Similarly, if a column is going to be used as a date it should be typed as a datetime column, not as a varchar. Here is the basic response to the records returned from the query:

0,1,0,1,1,0,,Blank,0,,0,0,,
this record failed for 3 reasons:
(1) The szF1 field is not a valid date (it is an empty string)
(2) The szF4 field is not a valid date (it is an empty string)
(3) the szF8 field is not a valid date (it is an empty string)

1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
this record faild for two reasons:
(1) The szF5 field is not numeric (it is an empty string)
(2) the szF6 field is not numeric (it is an empty string)

]

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

Now, you might be able to use the NULLIF function to get around these problems since all of these are manifest when the column is an EMPTY string. If you are wanting to test for NUMERIC columns you might also want to give a look to this article about problems with the "isNumeric" built-in function:

http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Error converting data type varchar to numeric

Hi,

Thank you in advance for your comments/suggestions. I am trying to create a View of a Table. The table is created by another application so I am unable to recreate it they way I want, also the data that is in the columns that I want to CAST are "numbers" not letters and will only be numbers. In the view I need certain columns to be CAST as numeric from varchar.

Here is the syntax that I am currently using:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time], szF2 AS [User Name], CAST(szF3 AS numeric) AS [Documents Indexed], CAST(szF4 AS datetime) AS [Logout Date/Time], CAST(szF5 AS numeric) AS [Documents Sent to QC], CAST(szF6 AS numeric) AS [Documents Reconciled], szF7 AS [Reject Reason], CAST(szF8 AS datetime) AS [Report Date]

FROM dbo.F_Report_Data AS a

WHERE (szF3 <> 'Blank')

When I open the view I get the error message about converting varchar to numeric.

Thanks,

Erik

Try running this query:

Code Snippet

SELECT CAST(szF1 AS datetime) AS [Login Date/Time],
szF2 AS [User Name],
-- CAST(szF3 AS numeric) AS [Documents Indexed],
szF3,
CAST(szF4 AS datetime) AS [Logout Date/Time],
-- CAST(szF5 AS numeric) AS [Documents Sent to QC],
-- CAST(szF6 AS numeric) AS [Documents Reconciled],
szF5,
szF6,
szF7 AS [Reject Reason],
CAST(szF8 AS datetime) AS [Report Date]
FROM dbo.F_Report_Data AS a
where isNumeric (szF3 + 'D0') = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0

And post any results that get returned.|||

I tried your suggestion and I got an error: "Error in list of function arguments: '=' not recognized. Unable to parse query text.

|||

It's likely because you have data in the szF5 or szF6 columns that can't be converted to numeric. For example, if I had the value aaa in szF5, I would get that error. More common is if I have a zero length string in the column, that can't be converted to numeric and I would get the error. A null would be fine but a zero length string would cause the error.

-Sue

|||

I would suggest (1) give the schema of the table and (2) give 5 sample rows of data from the table by doing a

select top 5 * from F_Report_Data

|||

The 3 columns that I want to cast as numeric have only numbers in them.

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

|||

The 3 columns that I want to cast as numeric have only numbers in them.

Code Snippet

1/24/2007 9:58:03 AM admin 207 1/24/2007 2:08:55 PM 0 0 1/24/2007 12:00:00 AM
1/24/2007 9:59:03 AM admin 0 1/24/2007 4:09:25 PM 1 0 Unable to read case number 1/24/2007 12:00:00 AM
1/24/2007 9:56:03 AM admin 0 1/24/2007 4:26:33 PM 0 3 1/24/2007 12:00:00 AM
1/25/2007 1:55:19 PM admin 0 1/25/2007 3:32:51 PM 0 0 1/25/2007 12:00:00 AM
1/25/2007 1:55:19 PM test 0 1/25/2007 4:11:09 PM 1 0 Unable to read case number 1/25/2007 12:00:00 AM

The items in bold are thecolumns that I am trying to covnert/cast as numeric.

Could you clarify by what you mean "Schema", it has been a while since my DB class and I am not a DBA. Every column is varchar(8000),null except for the PK which is (int, not null).

I awm giong to attempt to see if I can get the necessary results w/o convert/cast because there is supposed to be implicit conversion of varchar to numeric.

|||

Actually, you have answered the schema question -- all columns are varchar(8000) except for the PK which is integer -- a "wow" table. That should be enough for now. Try running this query and see if any results are returned:

Code Snippet

select left(szF1, 25) as szF1,
left(szF2, 25) as szF2,
left(szF3, 25) as szF3,
left(szF4, 25) as szF4,
left(szF5, 25) as szF5,
left(szF6, 25) as szF6,
left(szF7, 25) as szF7,
left(szF8, 25) as szF8
from dbo.F_Report_data
where isDate(szF1) = 0
or isNumeric (szF3 + 'D0') = 0
or isDate(szF4) = 0
or isNumeric (szF5 + 'D0') = 0
or isNumeric (szF6 + 'D0') = 0
or isDate(szF8) = 0

|||

Yes it returned a result, it's good that it returned a result but does that mean that we can/cannot convert/cast a varchar as a numeric? Thanks for your help!!

|||

Please post a sampling of the results that you received. It means that you will might either need to change the table or modify the way you display the data so that it is properly "clensed" -- you have dirty data.

|||

Here are the results:

Code Snippet

01/24/2007 09:58:03 AM admin 207 01/24/2007 02:08:55 PM 0 0 20070124
01/24/2007 09:59:03 AM admin 0 01/24/2007 04:09:25 PM 1 0 Unable to read case numbe 20070124
01/24/2007 09:56:03 AM admin 0 01/24/2007 04:26:33 PM 0 3 20070124
01/25/2007 01:55:19 PM admin 3 01/25/2007 03:32:51 PM 0 0 20070125

01/25/2007 01:55:19 PM test 0 01/25/2007 04:11:09 PM 1 0 Unable to read case numbe 20070125

| szf1| |szF2| szF3 |--szF4-| szF5 sz F6 |-szF7-| |szF8|

I just noticed that the query trimmed szF7 (Where it says "Unable to read case numbe"), I will need that field a little larger for the text. I never would have thought that there would be so much trouble to convert/cast a varchar to a numeric in a view.|||That did not display the same way it did on my screen when I was typing it. I hope it isn't too confusing.

|||

Can somebody point Erik to an article about cleaning up data? My tests weren't strong enough and I really am not interested in wasting Erik's time. I suspect that blanks in his data caused the isNumeric tests to fail.

Erik:

You can try this query; it will exhibit which test is failing:

Code Snippet

select isDate(rtrim(szF1)) as szF1isDate,
isNumeric (rtrim(szF3) + 'D0') as szF3IsNumeric,
isDate(rtrim(szF4)) as szF4IsDate,
isNumeric (rtrim(szF5) + 'D0') as szF5IsNumeric,
isNumeric (rtrim(szF6) + 'D0') as szF6IsNumeric,
isDate(rtrim(szF8)) as szF8isDate,
left(szF1, 30) as szF1,
left(szF2, 30) as szF2,
left(szF3, 30) as szF3,
left(szF4, 30) as szF4,
left(szF5, 30) as szF5,
left(szF6, 30) as szF6,
left(szF7, 30) as szF7,
left(szF8, 30) as szF8
from dbo.F_Report_data
where isDate(rtrim(szF1)) = 0
or isNumeric (rtrim(szF3) + 'D0') = 0
or isDate(rtrim(szF4)) = 0
or isNumeric (rtrim(szF5) + 'D0') = 0
or isNumeric (rtrim(szF6) + 'D0') = 0
or isDate(rtrim(szF8)) = 0

I feel like I need a fresh set of eyes on this at this point. Help?

|||

Here are the results of the query. I don't really know what they are saying though, could you give me pseudo code explanation of the query?

0,1,0,1,1,0,,Blank,0,,0,0,,
1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518

|||

Erik:

To me the problem here is that the columns are not sufficiently typed; this is a design problem that should be fixed. If a column is intended to be used as a number it should be typed as numeric. Similarly, if a column is going to be used as a date it should be typed as a datetime column, not as a varchar. Here is the basic response to the records returned from the query:

0,1,0,1,1,0,,Blank,0,,0,0,,
this record failed for 3 reasons:
(1) The szF1 field is not a valid date (it is an empty string)
(2) The szF4 field is not a valid date (it is an empty string)
(3) the szF8 field is not a valid date (it is an empty string)

1,1,1,0,0,1,01/25/2007 01:55:19 PM,admin,19,01/25/2007 04:11:43 PM,,,,20070125
this record faild for two reasons:
(1) The szF5 field is not numeric (it is an empty string)
(2) the szF6 field is not numeric (it is an empty string)

]

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 09:58:22 AM,1,0,Invalid case number,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

1,0,1,1,1,1,05/18/2007 08:37:01 AM,ATRAIN28,,05/18/2007 10:01:14 AM,0,1,,20070518
this record failed because:
(1) The szF3 field is not numeric (it is an empty string)

Now, you might be able to use the NULLIF function to get around these problems since all of these are manifest when the column is an EMPTY string. If you are wanting to test for NUMERIC columns you might also want to give a look to this article about problems with the "isNumeric" built-in function:

http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Error converting data type varchar to numeric

Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980s
Please don't multi-post. See answer in .programming.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980s
|||I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:

> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric" error
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know nuttin'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>
|||Help us help you:
http://www.aspfaq.com/etiquette.asp?id=5006
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:

> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric"
> error
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN
> WHEN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know
> nuttin'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>
|||"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
>I have to multi-post, or I don't get an answer.
> There is no answer over at the other section either, Tom--just a request
> to
> post data which I cannot post.
Don't MULTI-post, CROSS-post. (and only then to a select number of groups).

>
Greg Moore
SQL Server DBA Consulting
Email: sql (at) greenms.com http://www.greenms.com

Error converting data type varchar to numeric

Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980sPlease don't multi-post. See answer in .programming.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980s|||I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:

> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric" err
or
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WH
EN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know nutti
n'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>|||Help us help you:
http://www.aspfaq.com/etiquette.asp?id=5006
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:

> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric"
> error
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN
> WHEN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know
> nuttin'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>|||"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
>I have to multi-post, or I don't get an answer.
> There is no answer over at the other section either, Tom--just a request
> to
> post data which I cannot post.
Don't MULTI-post, CROSS-post. (and only then to a select number of groups).

>
Greg Moore
SQL Server DBA Consulting
Email: sql (at) greenms.com http://www.greenms.com

Error converting data type varchar to numeric

Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980sPlease don't multi-post. See answer in .programming.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
Hello:
I'm getting the famous "Error converting data type varchar to numeric" error
upon using an If, then statement.
I'm not too familiar with the use of CAST or CONVERT, which I understand
eliminates this sort of error.
How do I use either of those terms in the following SELECT CASE statement:
CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
'BNSHR' THEN UPR40600.DSCRIPTN
ELSE '0' END As [Payroll Description]
I don't get why SQL thinks I'm trying to do something numeric. All of the
fields in the above statement are string--not numeric. I don't know nuttin'
'bout no numbers!
Thanks!
childofthe1980s|||I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:
> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric" error
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN WHEN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know nuttin'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>|||Help us help you:
http://www.aspfaq.com/etiquette.asp?id=5006
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
I have to multi-post, or I don't get an answer.
There is no answer over at the other section either, Tom--just a request to
post data which I cannot post.
This is ridiculous.
childofthe1980s
"Tom Moreau" wrote:
> Please don't multi-post. See answer in .programming.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
> "childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
> message news:910EE9BB-3328-432C-9BC6-B06BF2C558CD@.microsoft.com...
> Hello:
> I'm getting the famous "Error converting data type varchar to numeric"
> error
> upon using an If, then statement.
> I'm not too familiar with the use of CAST or CONVERT, which I understand
> eliminates this sort of error.
> How do I use either of those terms in the following SELECT CASE statement:
> CASE UPR30300.PAYROLCD WHEN 'BREVN' THEN UPR40600.DSCRIPTN
> WHEN 'OVTMN' THEN UPR40600.DSCRIPTN WHEN 'BNDIS' THEN UPR40600.DSCRIPTN
> WHEN
> 'BNSHR' THEN UPR40600.DSCRIPTN
> ELSE '0' END As [Payroll Description]
> I don't get why SQL thinks I'm trying to do something numeric. All of the
> fields in the above statement are string--not numeric. I don't know
> nuttin'
> 'bout no numbers!
> Thanks!
> childofthe1980s
>
>|||"childofthe1980s" <childofthe1980s@.discussions.microsoft.com> wrote in
message news:BA8EFDC4-B4C3-4635-931F-90539E6DB06F@.microsoft.com...
>I have to multi-post, or I don't get an answer.
> There is no answer over at the other section either, Tom--just a request
> to
> post data which I cannot post.
Don't MULTI-post, CROSS-post. (and only then to a select number of groups).
>
Greg Moore
SQL Server DBA Consulting
Email: sql (at) greenms.com http://www.greenms.com