Formatting Numbers With Commas In TSQL
Jul 20, 2005
Once I've converted my floats to chars using STR, is there an easy way
to put commas in separating the thousands.
i.e. convert
53000000.12
to
53,000,000.12
I'm thinking I'll have to do it with a user defined function and the
various string functions myself but was wondering if anyone had an
easier way?
Cheers
Dave
View 6 Replies
ADVERTISEMENT
Feb 1, 2007
I have a report with a column which contains either a string such as "N/A" or a number such as 12. A user exports the report to Excel. In Excel the numbers are formatted as text.
I already tried to set the value as CDbl which returns error for the cells containing a string.
The requirement is to export the column to Excel with the numbers formatted as numbers and the strings such as "N/A' in the same column as string.
Any suggestions?
View 1 Replies
View Related
Jul 4, 2007
Hello Nice simple T-SQL question that will no doubt prove totally uncontroversial :) Anyone know the easiest way to get from:123456789to123,456,789in T-SQL? Currently I cast my int as money, use convert to varchar with style 1 and then lop off the .00. Is there an easier way? Two things before you get all upset and start squealing about front ends:1) These are admin functions that I am running from SSMS. I don't want to go to the bother of creating an application when SSMS is perfectly adequate for what I need (namely to-a-large-degree unformatted result sets).2) I'm not too fussed about it just curious. Ta & tra la!
View 2 Replies
View Related
Jul 23, 2005
I am pulling several numbers from a SQL table, adding them and doingvarious calculaitons. The numbers do not display a comma to separatethousands. What is a way to format this?
View 5 Replies
View Related
Jan 18, 2005
I am using a MS Access ADP connected to SQL Server Data
In a view I have the following formula:
dbo.tblQuoteItem.Cost + dbo.tblQuoteItem.Markup * dbo.tblQuoteItem.Cost * .01
this calculates cost + markup
I cannot get it to format in Currency
Ex:
Cost is $1.75
Markup is 2.00 (2%)
Total shows - 1.785000
I want $1.78
Also - I am using this formula to calculate the Quoted price for the Qty Entered
dbo.tblQuoteItem.Qty * dbo.tblQuoteItem.Cost + dbo.tblQuoteItem.Markup * dbo.tblQuoteItem.Cost * .01
Using a Qty of 2 for above, I get 3.535000
I want $3.53
Any help is appreciated - AB
View 2 Replies
View Related
May 20, 2008
I know this sounds like a basic question, but how do u add a leading 0 to a number, ie, 43 becomes 043
Thanks
View 6 Replies
View Related
May 21, 2008
On the layout page of Reporting Services I have a table. One of the cells contains the following expression:
=Sum(Fields!S2Agresso.Value)
S2Agresso is a decimal type. It contains values such as 0.00, 3.30 etc.
I need it to display it in the following fomat - 00.00
i.e
0.00 becomes 00.00
0.30 becomes 00.30
3.13 becomes 03.13
10.20 remains as 10.20
etc.
Can anyone help?
View 8 Replies
View Related
Aug 23, 2005
Hi,I have a table that has an ID field which is automatically incremented as each new record is added, so if I do a SELECT * FROM Table1 I get:ID, Name1, Billy2, Bob3, TonyYou get the idea. What I want to do is format the number differently when it's returned from an SQL statement so I get:ID, Name0001, Billy0002, Bob0003, TonySo I need something like SELECT FORMATNUMBER(ID, 4), Name FROM Table1 - Does anything like this exist?Little 'un.
View 2 Replies
View Related
Jul 17, 2000
What is the simplest way to format the 10 digit numeric string that represents a phone number, so that the result appearing on a web page looks like (xxx) xxx-xxxx. Should this take place in the database or out at the web server or where?
View 1 Replies
View Related
May 28, 2008
Here's my problem: I have to clean up a SQL Server 2005 database with a large number of phone number records (several hundred thousand). The records are of varchar datatype and contain phone numbers in every format imaginable. In fact, many records have written notes regarding the phone numbers after the numbers themselves. What I need to do is format all of the phone numbers to this format:
###-###-####-
Basically I'm figuring I need to do the following:
1. Strip all non-numeric characters from the record
2. Remove the 1 from any records that have a leading 1 (in many cases the records contain stuff like 1-888-555-1234)
3. Remove any digits following the first 10 digits (they don't want to keep any extensions - the formatting is more important)
4. Add dashes after the first three digits, after the second three and at the end of the phone number
This seems like a rather complex problem to me, and honestly I don't even know where to begin. I can accomplish this rather easily in javascript or C#, but writing SQL to solve this is beyond me. I'd really appreciate any help you guys can provide. Thanks alot!
View 14 Replies
View Related
Aug 9, 2002
How can I get the money datatype to return only two decimals instead of four?
View 2 Replies
View Related
Feb 8, 2007
Hi,
I'm using Reporting Services in conjunction with Analysis Services.
The problem I'm having is formatting numbers to be dollar amounts. I know how to set this in Reporting Services and when a data source was regular SQL, then everything was just fine. However, when I switch to Analysis Services the number would just stay the same.
i.e. "60.2" instead of "$60.20". The only thing I can think of is if Analysis Services is returning the number as a string for some reason, and RS won't format strings for currency.
Any thoughts? Thanks!
View 4 Replies
View Related
Mar 2, 2012
I'm trying to put conditional formatting on a field, that behaves as follows:
The data in the field is varchar, and sample data is either:
NULL
3.0 :0
11.7 :1 (these are ratios of a sort)
I want to evaluate the first 3 characters of the string as numbers.
Example:
Mid(fieldvalue,1,3) = "3.0" or "11."
Any data that is greater than 1.99, I want to make the background dark red, anything else including nulls, zebra formatting. I have the following expression built so far and it appears to work, except when the value is null. If the value is null, it leaves the background color white.
This is the warning: [rsRuntimeErrorInExpression] The BackgroundColor expression for the text box "Asthma" contains an error: Input string was not in a correct format.
=iif(
isnothing(Fields!Asthma.Value)
,(IIf(RowNumber(Nothing) Mod 2 = 0,"#b8cce4","#dbe5f1"))
,(iif(mid(Fields!Asthma.Value,1,3)>1.99
,"DarkRed"
,IIf(RowNumber(Nothing) Mod 2 = 0,"#b8cce4","#dbe5f1"))))
My logic is, if the field is null, zebra format, if mid of the value is > 1.99, dark red, everything else zebra formatting. As I said, this seems to work except for nulls.
View 2 Replies
View Related
Jul 20, 2005
Why does M$ Query Analyzer display all numbers as positive, no matterwhether they are truly positive or negative ?I am having to cast each column to varchar to find out if there areany negative numbers being hidden from me :(I tried checking Tools/Options/Connections/Use Regional Settings bothon and off, stopping and restarting M$ Query Analyer in betwixt, butno improvement.Am I missing some other option somewhere ?
View 7 Replies
View Related
Mar 11, 2008
I have a table with a column ID of ContentID. The ID in that column is all NULLs. I need a way to change those nulls to a number. It does not matter what type of number it is as long as they are different. Can someone point me somewhere with a piece of T-SQL that I could use to do that. There are over 24000 rows so cursor change will not be very efficient.
Thanks for any help
View 6 Replies
View Related
Mar 12, 2007
Hi,
I have table Article(ID,Title,FAID)
I need a query that will select all the Article.ID records where the FAID contains the number of the article ID
For exapmle, Article Table content is:
1, "Title1","2,6"
2, "Title2",""
3, "Title3","6,1"
6, "Title6","2"
Lets say I want to get all titles of article ID 1. I am going to its FAID which is "2,6"
So the query will return : "Title2", "Title6"
Can you advice how to write this? I can do a walk around solution where I will open a new table name FA but I rather not to.
View 3 Replies
View Related
Feb 18, 2008
I have a normal nvarchar(50) field in a table that has a single comma in it but when i read it using OleDbDataReader the comma gets removed.
any ideas what i am doing wrong ?
many thanks
View 4 Replies
View Related
May 10, 2008
Hi
I have an excel file with 2 columns:
article art_group
kb art,tp,key
portal grup,port,li
I have a table in the database called tb_artGroups with the columns
article art_group
Now for each row in the excel i have to write the values after the comma in a new row such as:
article art_group
kb art
kb tp
kb key
portal grup
etc...
How can i do that with SSIS?
Thanks
Whisky-my beloved dog who died suddenly on the 29/06/06-I miss u so much.
View 4 Replies
View Related
Sep 4, 2007
I am using SQL 2005 and have a query that returns seven columns of data. In one the columns, the results contains commas. For example, one of the results is 'brooke, nick, dustin, and me.jpg'. The results are saved into a .csv file so it can be imported into Excel. The user named the file with the commas and I need to preserve the original file name.
My question:
Is there some way to format the data inside of SQL so that when it gets saved as a .csv file, the extra commas don't throw off the column layout?
I don't want to have to manually clean up possibly several hundred rows of data everytime I run the query.
Thanks in advance.
View 4 Replies
View Related
Feb 21, 2007
I have an 'ID' column. I'm up to about ID number 40000, but not all are in use, so ID 4354 might not be in any row. I want a list of all numbers which aren't in use. I want to write something like this:
select [numbers from 0 to 40000] where <number> not in (select distinct id from mytable)
but don't know how. Any clues?
View 1 Replies
View Related
Mar 27, 2007
I'm trying to write data to excel from an ssis component to a excel destination.
Even thought I'm writing numerics, every cell gets this error with a green tag:
Convert numbers stored as text to numbers
Excel Cells were all pre-formated to accounting 2 decimal, and if i manually type the exact data Im sending it formats just fine.
I'm hearing this a common problem -
On another project I was able to find a workaround for the web based version of excel, by writing this to the top of the file:
<style>.text { mso-number-format:@; } </style>
is there anything I can pre-set in excel (cells are already formated) or write to my file so that numerics are seen as numerics and not text.
Maybe some setting in my write drivers - using sql servers excel destination.
So close.. Thanks for any help or information.
View 1 Replies
View Related
Mar 7, 2000
Do anyone know of a function, that I can use to removed commas
from a string? eg. "The lady, cross the road" should be "The lady cross the road"
Thanks, Vic
View 2 Replies
View Related
Jul 30, 1999
Hello all,
I am using SQL Server 6.5 SP5a.
I have to use bcp to import two text files everyday for database update. The problem is that some of the character fields that are being imported have double-quotes and/or commas in them. When these are imported into the SQL Server tables additional double quotes are being added into these strings.
Example:
INCOMING STRING = a"a
IMPORTED STRING = "a""a"
INCOMING STRING = b,b
IMPORTED STRING = "b,b"
I have searched through BOL and have not been able to find any information.
Does anyone know what is causing this and if so how to correct it?
Thanks,
Bryan Ziel
View 3 Replies
View Related
Nov 17, 2014
I have a hierarchy of product categories and I want to string them together to show the complete path (breadcrumbs) to the item. Each category/subcat must be separated buy a comma. The catch is that not all items have the same number of cats/subcats. Here is what I am currently doing, but as you can see, this results in extra commas where the subcats are null.
Code:
create table #ItemCat(
itemNo int,
Cat varchar(50),
SubCat1 varchar(50),
SubCat2 varchar(50)
[Code] ....
Is there some way to concatenate these, separated by commas, but ignoring the NULL fields? For example, ItemNo 1 should show "Kitchen, Appliances"
View 3 Replies
View Related
May 15, 2008
I'm trying to export a query to a csv file. Everything works great
until I hit the name field. Is there a way to remove commas from a select statement.
Here's what my Data looks like
Item # | Name
-------------------------
1111 | Acme, Inc
1112 | Test Company, Inc
I'd like it to print out as
Item # | Name
-------------------------
1111 | Acme Inc
1112 | Test Company Inc
Thanks for any help in advance.
View 1 Replies
View Related
Jan 1, 2008
Hey everyone. I've never posted on this site before so if I miss anything, please let me know.
I need to order the following data
18
14,15
13.2
14.2
15,16
15
0
14.1
12
6
15,16,18
11
16
15,17
13
14
14,15.2
17
into this order:
0
6
11
12
13
13.2
14
14.1
14.2
14,15
14,15.2
15
15,16
15,16,18
15,17
16
17
18
Because the data contains commas, I've had to change the data type to varchar. I've seen several instances of PATINDEX used however I have not ran across any of them that would put the above in the order in which I need. Btw, I have about 20 columns with this type of data and I eventually plan to use the results of each column to populate dropdownlists . Thank you all in advance.
View 11 Replies
View Related
Feb 5, 2015
I have a simple statement where I am trying to remove all commas that may be in the xn_workordeld column.
SELECT
xn_workordeld = case replace(xn_workordeld, ',', '') as "WORKORDER LD"
from workorder
View 3 Replies
View Related
Jun 3, 2008
Have a column in my DB called _Venue, which has been populated with address information separated by commas, like this:
Address1,address2,address3,address4
The address has sometimes only a few lines, for example I may have just Address1 or just address1 and address2 filled etc.
I need to write a query that will individually select addressX, so I can pick and choose what part of the full address to use.
Can these be done?
Thanks in advance.
View 9 Replies
View Related
Mar 24, 2006
Hi,
Can you help
I have a string that has multiple commas:
'AAA,BBB,CCC,DDD,EEE,...'
I need to pick any characters between commas or find all commas positions.
View 4 Replies
View Related
Jul 13, 2007
I am trying to create a SSIS package with a csv flat file for the both the destination and source. I cannot control the source file. I need to be able to handle an extra comma in the source file which occasionally contains suffixes i.e. {John, Smith, Jr,} which could cause some records to be 9 fields and others 10. Any ideas?
View 1 Replies
View Related
Dec 19, 2007
How can I convert a field with commas, cents and decimal to a numeric without commas and decimals and cents...?
Sample nvarchar values to desired output (integer whole value, truncated or rounded doesn't matter):
0.00 to 0
14,000.04to 14000
139,234.31to 139234
14,017,300.00to 14017300
View 2 Replies
View Related
Mar 7, 2008
Hi All,
Is there a way to remove Leading & Trialing Commas (,) in a string using SQL code ? Appreciate any thoughts.
Thanks
View 10 Replies
View Related
Jun 26, 2007
HI
I have three different columns as email1,email2 , email3.I am concatinating these columns into one i.e EMail like
select ISNULL(dbo.tblperson.Email1, N'') + ';' + ISNULL(dbo.tblperson.Email2, N'') + ';' + ISNULL(dbo.tblperson.Email3, N'') AS Email from tablename.
One eg of the output of the above query when email2,email3 are having null values in the table is :
jacky_foo@mfa.gov.sg;;
means it is inserting semicoluns whenever there is a null value in the particular column. I want to remove this extra semicolumn whenever there is null value in the column.
Please let me know how can i do this
View 6 Replies
View Related