SQL Query Error - Error converting data type varchar to numeric.

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
409
I appreciate this is not an excel/VBA type query but can't find an obvious forum to post it? hopefully someone can help?

I have this SQL query which works when applied to non-numeric data (text) but I get the below error when using the code on numeric data

error - Error converting data type varchar to numeric?

Code:
 , CASE ISNULL(ProductRate, 'NULLVALUE') 
WHEN 'NULLVALUE' THEN ''
ELSE ProductRate
END AS ProductRate

On text fields it converts NULL to Blank, can anyone help?

Thank you
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Converting should help, because you need "empty" string in the case of NULL of a numeric field value as return. That's why SQL get confused.

Additional note - I don't think you need CASE WHEN. ISNULL would do it alone.

Code:
, ISNULL(CONVERT(char, ProductRate), '') AS ProductRate
 
Last edited:
Upvote 0
Converting should help, because you need "empty" string in the case of NULL of a numeric field value as return. That's why SQL get confused.

Additional note - I don't think you need CASE WHEN. ISNULL would do it alone.

Code:
, ISNULL(CONVERT(char, ProductRate), '') AS ProductRate

Perfect, Thank you so much
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,553
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top