Reputation: 365
I'm trying to convert a standard SQL query to a LINQ to SQL query.
I was wondering what the LINQ equivalent of the T-SQL function STR() is?
STR (T-SQL)
Returns character data converted from numeric data.
Syntax STR(float_expression[, length[, decimal]])
Arguments float_expression Is an expression of approximate numeric (float) data type with a decimal point. Do not use a function or subquery as the float_expression in the STR function. length Is the total length, including decimal point, sign, digits, and spaces. The default is 10. decimal Is the number of places to the right of the decimal point. Return Types char
I'm trying to explicitly set the number of decimal places for a field.
Please and thank you!
(I've tried Googling around, but Google keeps on translating str as "string" even with double quotes aroud str)
EDIT
I've tried .ToString("N2") which is exactly what I want, but LINQ isn't able to translate it.
EDIT
Clarification, I have a SQL field that is a double. I have to append/truncate to 2 decimal places. After that, I will append it with an additional string. So therefore, I believe I do need to convert it to a string. This is because I need to compare that generated string with another field that is of type varchar. (I know this is idiotic because they should be the same type, etc, but I can't change the design of the database).
Upvotes: 0
Views: 938
Reputation: 48422
Huy,
There is a product (which I have no association with) that translates T-SQL queries into Linq queries. The name is Linqer (http://www.sqltolinq.com/). It's very inexpensive and has been a help to me in converting some of my more difficult queries.
Randy
Upvotes: 3
Reputation: 116498
The first thing that comes to mind is ToString()
.
See the link for some examples of how to format it to your liking, or refer to the following:
However, your statement here leads me to question whether you really want a string or not:
I'm trying to explicitly set the number of decimal places for a field.
Perhaps you could clarify what exactly you're trying to do?
Upvotes: 0