mvkannan
asked on
Comma seperator in results
While fetching the values from the table I want the result with comma seperator. The data type of the field is decimal
For ex the value in the table is 10000. While fetching I want the result as 10,000.
For ex the value in the table is 10000. While fetching I want the result as 10,000.
ASKER
Hi Hilaire
I don't want the values in the table to have comma seperated. We need this only for the report. We are giving the SQL queries to the user. In the result users want to see the values with comma seperation. So it need to be done only in the query.
I don't want the values in the table to have comma seperated. We need this only for the report. We are giving the SQL queries to the user. In the result users want to see the values with comma seperation. So it need to be done only in the query.
>>We are giving the SQL queries to the user.<<
Do you mean you give the resultset (the output of the query) or the query iself ?
If you give the query, I guess the user puts it in a reporting tool. Most reporting tools (that's what I called the front-end side) have standard functions to deal with presentation issue. You can even change display format (number of decimal places, thousands separator) with two button clics.
If you give the query output, just save the output as a CSV file in QA (or copy-paste to Excel),
open the file with Excel, change column format to "Number" and choose a display style that fits the user's requirements. Then give the XL file ...
If none of the solutions above fits your needs,
I should be able to come with a T-SQL function, but it will make query performance suck, (mostly if the query fetches a lot of data).
Just post sample numbers in both current and expected format (i need to know if there will be decimal places, if you need a fixed number of decimal places ...)
Do you mean you give the resultset (the output of the query) or the query iself ?
If you give the query, I guess the user puts it in a reporting tool. Most reporting tools (that's what I called the front-end side) have standard functions to deal with presentation issue. You can even change display format (number of decimal places, thousands separator) with two button clics.
If you give the query output, just save the output as a CSV file in QA (or copy-paste to Excel),
open the file with Excel, change column format to "Number" and choose a display style that fits the user's requirements. Then give the XL file ...
If none of the solutions above fits your needs,
I should be able to come with a T-SQL function, but it will make query performance suck, (mostly if the query fetches a lot of data).
Just post sample numbers in both current and expected format (i need to know if there will be decimal places, if you need a fixed number of decimal places ...)
I know your first sample has no decimal places,
but decimal datatype could be decimal(30,10) as well ...
but decimal datatype could be decimal(30,10) as well ...
ASKER
>>We are giving the SQL queries to the user.<<
We give the SQL queries to the user. They will run the query in the query analyser and will save the result to excel file. They don't want to format the excel cells. So when I run the query the result should come with comma seperated.
We give the SQL queries to the user. They will run the query in the query analyser and will save the result to excel file. They don't want to format the excel cells. So when I run the query the result should come with comma seperated.
>>They don't want to format the excel cells<<
If I give you code to build formatted strings,
EXCEL will "see" those numbers as strings, and thus the users will lose the ability to make a SUM, to sort numbers by value (values will sort alphabetically instead, ie "99" > "10000"), to build pivot tables, ....
And in the end they'll ask you to remove the commas or make a replace by themselves
Again, this should be handled on the front-end side.
You could set up a VBA macro to make the formatting so that they don't have to do it manually each and every time the reports is refreshed.
If you really need a T-SQL Solution (inappropriate IMHO), I need to know if the numbers have decimal places or are pure integers.
Hilaire
If I give you code to build formatted strings,
EXCEL will "see" those numbers as strings, and thus the users will lose the ability to make a SUM, to sort numbers by value (values will sort alphabetically instead, ie "99" > "10000"), to build pivot tables, ....
And in the end they'll ask you to remove the commas or make a replace by themselves
Again, this should be handled on the front-end side.
You could set up a VBA macro to make the formatting so that they don't have to do it manually each and every time the reports is refreshed.
If you really need a T-SQL Solution (inappropriate IMHO), I need to know if the numbers have decimal places or are pure integers.
Hilaire
ASKER
The data type for that field is decimal. But some values will have decimal and some will be whole no.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is generally admitted that display issue are best handled on the front-end side.
To transform a numeric value in SQL Server, you'd have to convert to another datatype (varchar)
The algorythm could be rather complex is the numeric values ahve decimal places.
Is there a particular reason why you'd need it in SQL Server ?
Hilaire