Error Converting Data Type Nvarchar To Float Vb.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Happens occasionally: “Error converting data type nvarchar to float” up vote 2 down vote favorite Here is my SQL query: SELECT (CAST(CAST([rssi1] AS float) AS INT))*-1, CONVERT(VARCHAR(10), [date], 110) FROM history WHERE id IN ( SELECT TOP 8 id FROM history WHERE ([siteName] = 'CAL00022') ORDER BY id DESC ) ORDER BY date ASC Most of the time, it works fine. Sometimes, I get this error: Server Error in '/' Application. Error converting data type nvarchar to float. 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 nvarchar to float. The table is this: sql sql-server casting share|improve this question asked Jul 4 '13 at 22:21 Ned 51041227 Is that your entire table? You probably have at least one value in rssi1 that isn't a valid float.. –Blorgbeard Jul 4 '13 at 22:26 Well, that's obviously not the data that's causing the problem. What does SELECT * FROM history ORDER BY id show you about the rest of the data? –Ken White Jul 4 '13 at 22:28 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted Terrible when you distrust the handling of real numbers in your chosen engine so much that you'll store them in nvarchars! I've retrieved enough 1.000000000001's to sympathise, but don't much like this solution either. Identifying your invalid records, as per John's answer, is necessary but you may not be in a position to personally do anything about it anyway. What you've provided is a SELECT statement that sometimes fails and, so, I address that failure. Checking that the value of rssi1 is numeric prior to attempts at casting can avoid the error you're
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users http://stackoverflow.com/questions/17478755/happens-occasionally-error-converting-data-type-nvarchar-to-float Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Getting Error: “Error converting data type nvarchar to numeric” in SQL up http://stackoverflow.com/questions/11014322/getting-error-error-converting-data-type-nvarchar-to-numeric-in-sql vote 3 down vote favorite I am passing 4 Parameters to an asp.net Webservice. This is my Code so far: Webmethod: [ScriptMethod(ResponseFormat = ResponseFormat.Json)] [WebMethod] public List
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Data Access/SQL Server, SQL Server Express, and SQL Compact Edition/how to convert from nvarchar to float how to convert from nvarchar to float [Answered]RSS 27 replies Last https://forums.asp.net/t/1860556.aspx?how+to+convert+from+nvarchar+to+float post Nov 28, 2012 10:12 PM by Chen Yu - MSFT ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply jfr Member 51 Points 512 Posts how to convert from nvarchar to float Nov 22, 2012 04:46 AM|jfr|LINK Hi! How to convertnvarchar to float, if the numbers are like 3,14 saved, but they should be converted error converting like 3.14 Reply Usha82 Member 540 Points 149 Posts Re: how to convert from nvarchar to float Nov 22, 2012 04:54 AM|Usha82|LINK select cast(replace('3,14',',','.') AS decimal (10,2)) Reply dhol.gaurav Contributor 2760 Points 771 Posts Re: how to convert from nvarchar to float Nov 22, 2012 04:56 AM|dhol.gaurav|LINK Check below query it may help you SELECT CAST( REPLACE('3,15', ',','.') AS float) let me know if any query Thanks, Gaurav error converting data Dhol Skype ID : dhol.gaurav Reply jfr Member 51 Points 512 Posts Re: how to convert from nvarchar to float Nov 22, 2012 05:35 AM|jfr|LINK SELECT CAST( REPLACE(field, ',','.') AS float) from table Error converting data type nvarchar to float. Reply dhol.gaurav Contributor 2760 Points 771 Posts Re: how to convert from nvarchar to float Nov 22, 2012 05:40 AM|dhol.gaurav|LINK Can you share you data here, i thought you have some other char into database also, so you MUST have to replace thoes char also let me know if any query Thanks, Gaurav Dhol Skype ID : dhol.gaurav Reply jfr Member 51 Points 512 Posts Re: how to convert from nvarchar to float Nov 22, 2012 05:51 AM|jfr|LINK is this query "SELECT CAST( REPLACE(field, ',','.') AS float) from table" correct? I have only one commar in each data Reply dhol.gaurav Contributor 2760 Points 771 Posts Re: how to convert from nvarchar to float Nov 22, 2012 05:55 AM|dhol.gaurav|LINK Query is look like ok, can you tell me have you more then one "," comma into value?? let me know if any query Thanks, Gaurav Dhol Skype ID : dhol.gaurav Reply jfr Member 51 Points 512 Posts Re: how to convert from nvarchar to floa