[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Error converting data type varchar to numeric

childofthe1980s

3/19/2007 1:20:00 AM

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]

Thanks!

childofthe1980s
6 Answers

Tom Moreau

3/19/2007 1:36:00 AM

0

How about posting the DDL for the UPR30300 and UPR40600 tables?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada

"childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
message news:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]

Thanks!

childofthe1980s


childofthe1980s

3/19/2007 1:44:00 AM

0

Hi Tom:

Hmm...I'm not sure how to post this. All of the characters types within the
formula that I posted were string characters. I'm sorry. I'm not sure what
else to post, really.

childofthe1980s

"Tom Moreau" wrote:

> How about posting the DDL for the UPR30300 and UPR40600 tables?
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
>
> "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> message news:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]
>
> Thanks!
>
> childofthe1980s
>
>
>

Tom Moreau

3/19/2007 2:02:00 AM

0

Please post the CREATE TABLE statements for the tables involved. If you
have sample data, that would help, too.

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada

"childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
message news:E401A4E6-FF78-4D17-89F6-2CDD7BC4125A@microsoft.com...
Hi Tom:

Hmm...I'm not sure how to post this. All of the characters types within the
formula that I posted were string characters. I'm sorry. I'm not sure what
else to post, really.

childofthe1980s

"Tom Moreau" wrote:

> How about posting the DDL for the UPR30300 and UPR40600 tables?
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
>
> "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> message news:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]
>
> Thanks!
>
> childofthe1980s
>
>
>


childofthe1980s

3/19/2007 2:37:00 AM

0

Boy, I don't know how to do any of that.

I'll have to check another avenue.

Thanks, anyway

childofthe1980s

"Tom Moreau" wrote:

> Please post the CREATE TABLE statements for the tables involved. If you
> have sample data, that would help, too.
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
>
> "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> message news:E401A4E6-FF78-4D17-89F6-2CDD7BC4125A@microsoft.com...
> Hi Tom:
>
> Hmm...I'm not sure how to post this. All of the characters types within the
> formula that I posted were string characters. I'm sorry. I'm not sure what
> else to post, really.
>
> childofthe1980s
>
> "Tom Moreau" wrote:
>
> > How about posting the DDL for the UPR30300 and UPR40600 tables?
> >
> > --
> > Tom
> >
> > ----------------------------------------------------
> > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > SQL Server MVP
> > Toronto, ON Canada
> >
> > "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> > message news:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]
> >
> > Thanks!
> >
> > childofthe1980s
> >
> >
> >
>
>
>

Tom Moreau

3/19/2007 2:44:00 AM

0

Well, you had to create the table somehow. How about right-clicking on the
table, and clicking on Script table as...

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada

"childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
message news:45FAF32D-C3F9-4B18-AE9B-2277107D6624@microsoft.com...
Boy, I don't know how to do any of that.

I'll have to check another avenue.

Thanks, anyway

childofthe1980s

"Tom Moreau" wrote:

> Please post the CREATE TABLE statements for the tables involved. If you
> have sample data, that would help, too.
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
>
> "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> message news:E401A4E6-FF78-4D17-89F6-2CDD7BC4125A@microsoft.com...
> Hi Tom:
>
> Hmm...I'm not sure how to post this. All of the characters types within
> the
> formula that I posted were string characters. I'm sorry. I'm not sure
> what
> else to post, really.
>
> childofthe1980s
>
> "Tom Moreau" wrote:
>
> > How about posting the DDL for the UPR30300 and UPR40600 tables?
> >
> > --
> > Tom
> >
> > ----------------------------------------------------
> > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > SQL Server MVP
> > Toronto, ON Canada
> >
> > "childofthe1980s" <childofthe1980s@discussions.microsoft.com> wrote in
> > message news:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]
> >
> > Thanks!
> >
> > childofthe1980s
> >
> >
> >
>
>
>


Rahul

3/19/2007 4:57:00 AM

0

On Mar 19, 7:43 am, "Tom Moreau" <t...@dont.spam.me.cips.ca> wrote:
> Well, you had to create the table somehow. How about right-clicking on the
> table, and clicking on Script table as...
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Toronto, ON Canada
>
> "childofthe1980s" <childofthe19...@discussions.microsoft.com> wrote in
> messagenews:45FAF32D-C3F9-4B18-AE9B-2277107D6624@microsoft.com...
> Boy, I don't know how to do any of that.
>
> I'll have to check another avenue.
>
> Thanks, anyway
>
> childofthe1980s
>
>
>
> "Tom Moreau" wrote:
> > Please post the CREATE TABLE statements for the tables involved. If you
> > have sample data, that would help, too.
>
> > --
> > Tom
>
> > ----------------------------------------------------
> > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > SQL Server MVP
> > Toronto, ON Canada
>
> > "childofthe1980s" <childofthe19...@discussions.microsoft.com> wrote in
> > messagenews:E401A4E6-FF78-4D17-89F6-2CDD7BC4125A@microsoft.com...
> > Hi Tom:
>
> > Hmm...I'm not sure how to post this. All of the characters types within
> > the
> > formula that I posted were string characters. I'm sorry. I'm not sure
> > what
> > else to post, really.
>
> > childofthe1980s
>
> > "Tom Moreau" wrote:
>
> > > How about posting the DDL for the UPR30300 and UPR40600 tables?
>
> > > --
> > > Tom
>
> > > ----------------------------------------------------
> > > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > > SQL Server MVP
> > > Toronto, ON Canada
>
> > > "childofthe1980s" <childofthe19...@discussions.microsoft.com> wrote in
> > > messagenews:3D6C9401-BC39-4EFC-91D7-9415FBD68252@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]
>
> > > Thanks!
>
> > > childofthe1980s- Hide quoted text -
>
> - Show quoted text -


Hi,

Use it ---

CASE Cast(UPR30300.PAYROLCD as Char(5))
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]


Rahul