ok, i have a column of data type money and the data that is found in there is entered like this
1.1490
1.2340
1.0590
0.5990
0.5380
what i want to do is have it formatted as such
1149
1234
1059
0599
0538
ive tried using cast, convert, from money to varchar and simplying multiplying the field, replace and trunc but its not happening !!! any code help would be great!
thanks
andreas
7 2216
hi andreas,
Try this : -
declare @a varchar(10)
-
declare @b varchar(10)
-
set @a= convert(varchar(10),1.1490)
-
set @b=Replace(@a,'.','')
-
select left(@b,4)
-
Let me know if this has solved your problem. Gud Luck!
Cheers,
jai
ok, i have a column of data type money and the data that is found in there is entered like this
1.1490
1.2340
1.0590
0.5990
0.5380
what i want to do is have it formatted as such
1149
1234
1059
0599
0538
ive tried using cast, convert, from money to varchar and simplying multiplying the field, replace and trunc but its not happening !!! any code help would be great!
thanks
andreas
Recommended pattern is that any data formatting should be performed on the client side.
If you still want to format the data on server, use the following script: - declare @t table (price money)
-
insert @t values (1.1490)
-
insert @t values (1.2340)
-
insert @t values (1.0590)
-
insert @t values (0.5990)
-
insert @t values (0.5380)
-
-
select formatted_price = isnull(replicate('0', 4-len(price)), '') + price
-
from
-
(select price = convert(varchar(10), convert(int,price*1000))
-
from @t) source
all of the code works perfectly fine, the thing is thought, that in dbo.vwCurrentFuelPrice there has a column CurrentPrice that i want to format in the way i described above. i want to be able to get it every time without having to manually enter the prices 1.1490 etc. thats how it gets put in if you get my drift.. thanks!
all of the code works perfectly fine, the thing is thought, that in dbo.vwCurrentFuelPrice there has a column CurrentPrice that i want to format in the way i described above. i want to be able to get it every time without having to manually enter the prices 1.1490 etc. thats how it gets put in if you get my drift.. thanks!
heres the offending code
declare @a varchar(10)
declare @b varchar(10)
SELECT DateEntered, dbo.Site.SiteCode AS SiteCode, ('0' + DepartmentID) AS FuelCode, convert(varchar(10),CurrentPrice)
FROM dbo.vwCurrentFuelPrice, dbo.Site
WHERE dbo.vwCurrentFuelPrice.SiteID = dbo.Site.SiteID
set @a = convert(varchar(10),dbo.vwCurrentFuelPrice.Current Price)
set @b =Replace(@a,'.','')
select left(@b,4)
that should help explain a bit about what im trying to achieve
Try this:
[PHP]
select right('0000' + convert(varchar(10), convert(int, CurrentPrice * 1000)),4) from dbo.vwCurrentFuelPrice[/PHP]
legend! thanks heaps buddy
=)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: |
last post by:
Does anyone know an easy way to put a current gold price on your own
website? I've seen the graphic methods that Kitco.com offers, but I'd
rather have it pull the value from some gold market...
|
by: cwbp17 |
last post by:
Have a datagrid that displays the price column in this format $12,400.00 from
a table.
Went to the Property Builder of the datagrid and selected the Price column
and changed the Data formatting...
|
by: Gigi.com |
last post by:
Hi All.
I need some help trying to pull prices from a price matrix. Here's an
example:
>>>> 1000 1500 2000 2500
-----------------------------------------
1000 ¦ 10.20 ...
|
by: cwbp17 |
last post by:
Have a datagrid that displays the price column in this format $12,400.00 from
a table.
Went to the Property Builder of the datagrid and selected the Price column
and changed the Data formatting...
|
by: geoffrey.slinker |
last post by:
I have developed a new type of chart. It shows the relative volume for
each price during an interval.
http://home.att.net/~geoffrey.slinker/maverick/VolumeBars.html
I am a Data Visualization...
|
by: HandersonVA |
last post by:
should I set to "0" as a default value on a quantity and a price field
or set to "null"?
if a user enter nothing on the quantity or price field on a web
browser, should I treat it as null or "0"?...
|
by: menyki |
last post by:
am writing a program to determine the best price that will attract maximum demand. first i had to generate random number to enable me determine the price and quantity demanded at the particular...
|
by: dancole42 |
last post by:
I have an InvoiceLines subform on an invoice table. In the subform, I
have the following fields that are bound to the actual InvoiceLines
table:
Class (the type of product)
Product (the...
|
by: fniles |
last post by:
Say price = 4179.00 or 4179
In VB6, when I do Format(price, "#.0"), it returns 4179.0, but in VB.NET
when I do String.Format(price, "#.0"), it returns 4179.00.
How can I do Format(price, "#.0") in...
|
by: printline |
last post by:
I am need of a simple price calculation script that will give users a price on a Printed Circuit Board.
Here is an example:
I have a panel that is 18 dm˛. A customers wants 1 PCB that is 100mm...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |