0

In my asp web project i've got some double type variables. This variables i have too store in sql server database. I found in the internet information that float data type will be best. BUT Sql Server accept numbers with comma like "1,3" "12,7". In asp code i've got double variables with point like "1.3" "2.7" etc... When I'am trying using numbers with comma in asp net, i'am receiving error "identifier expected". I was trying changed data type to nvachar in sql server, and works, but there is a lot of problems with using query and "Order BY columnNameWithDoubleNumber DESC" beacuse i 'am receiving results I wasn't expected. Please, could You help me with that ? :/

4
  • please post your query. Commented Mar 31, 2014 at 23:23
  • Why are You asking for query ?. Query works fine, problem is with numbers, i dont know how using numbers with comma in asp.net, or how to convert number with comma into nukbers with point i Sql Server. Commented Mar 31, 2014 at 23:29
  • 1
    This sounds like a collation problem. What is your sql server collation set to? Commented Mar 31, 2014 at 23:39
  • Honestly, i dont know anything about Server collation.. How can I check that ? Commented Mar 31, 2014 at 23:43

1 Answer 1

1

You are mixing up the numbers with the text representation of the numbers. As a number, the value doesn't have any specific format, it's only when you turn the number into a string or parse a string into a number that the cultural settings come into play.

If you store the number as text in the database, it will be compared as text when you try to sort it. You should store the number as a number, then it will be sorted correctly.

If you have a double value in your ASP.NET code and send that in a query using a parameter, there is no cultural issues with the decimal separator.

If you are concatenating the decimal value into an SQL query (which is not recommended), you would use a period as decimal separator. SQL always uses period as decimal separator, just as with a double literal in your ASP.NET code.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, You can call me "The biggest idiot in the world". Off course i'am using parameters for query, but i never checked that there will be any cultural issues with separators :/. I was checking that only in Server MAnagement Studio. I cheked that after reading Your post, so thank You very much for answer !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.