473,769 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server and VBscript decimal problem

I am pulling a decimal value from SQL server and trying to use the format
currency and format number function. I am using these values in a large
string of HTML to be used in a CDONTS Email. If I use the code fragment
below the price variable, which is 3.92 in the database, shows up as £392.
When the formatcurrency is removed it is displayed as 3.92 but!!!! if I
concatenate a "£" it displays £392. I have read some posts about VBscript
not liking decimals, are there any ways around this. I have tried a
conversion to the money datatype, used a variety of csng and cdbl functions.
The odd thing is other numbers from the same column in the recordset format
correctly. The other thing is that variable 'price' is used elsewhere and
calculates correctly it seems VBscript just doesn't like converting it to a
string. Totally stumped!! Can anyone help.

HTML = HTML & "<td>" & formatcurrency( price) & "(&euro;" &
formatnumber(pr ice*rate,2) & ")" & "</td>"
Jul 19 '05 #1
6 8258
Don't use the money datatype, use numeric or decimal. Regional settings can
play a factor if you use money/smallmoney... when you insert one number you
might get something totally different.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Chris Kennedy" <ch**********@c ybase.co.uk> wrote in message
news:e4******** ******@tk2msftn gp13.phx.gbl...
I am pulling a decimal value from SQL server and trying to use the format
currency and format number function. I am using these values in a large
string of HTML to be used in a CDONTS Email. If I use the code fragment
below the price variable, which is 3.92 in the database, shows up as £392.
When the formatcurrency is removed it is displayed as 3.92 but!!!! if I
concatenate a "£" it displays £392. I have read some posts about VBscript
not liking decimals, are there any ways around this. I have tried a
conversion to the money datatype, used a variety of csng and cdbl functions. The odd thing is other numbers from the same column in the recordset format correctly. The other thing is that variable 'price' is used elsewhere and
calculates correctly it seems VBscript just doesn't like converting it to a string. Totally stumped!! Can anyone help.

HTML = HTML & "<td>" & formatcurrency( price) & "(&euro;" &
formatnumber(pr ice*rate,2) & ")" & "</td>"

Jul 19 '05 #2
Sorry about the multipost. I have never really thought it as a problem as I
have always done it in the past and often got answers from different people.

In regards to the question the datatype in SQL Server is decimal, I only
converted it to money as workaround that might point me in the right
direction. I would think using the cdbl function would work as it has in
similar situations where ASP sees any calculation with a decimal as a type
mismatch. Any ideas.
"Aaron [SQL Server MVP]" <te*****@dnartr eb.noraa> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Don't use the money datatype, use numeric or decimal. Regional settings can play a factor if you use money/smallmoney... when you insert one number you might get something totally different.

--
http://www.aspfaq.com/
(Reverse address to reply.)


"Chris Kennedy" <ch**********@c ybase.co.uk> wrote in message
news:e4******** ******@tk2msftn gp13.phx.gbl...
I am pulling a decimal value from SQL server and trying to use the format currency and format number function. I am using these values in a large
string of HTML to be used in a CDONTS Email. If I use the code fragment
below the price variable, which is 3.92 in the database, shows up as £392. When the formatcurrency is removed it is displayed as 3.92 but!!!! if I
concatenate a "£" it displays £392. I have read some posts about VBscript not liking decimals, are there any ways around this. I have tried a
conversion to the money datatype, used a variety of csng and cdbl functions.
The odd thing is other numbers from the same column in the recordset

format
correctly. The other thing is that variable 'price' is used elsewhere and calculates correctly it seems VBscript just doesn't like converting it

to a
string. Totally stumped!! Can anyone help.

HTML = HTML & "<td>" & formatcurrency( price) & "(&euro;" &
formatnumber(pr ice*rate,2) & ")" & "</td>"


Jul 19 '05 #3
> Any ideas.

Only if you show your table structure, sample data, ASP code, and desired
results.

--
http://www.aspfaq.com/
(Reverse address to reply.)
Jul 19 '05 #4
Chris Kennedy wrote:
Sorry about the multipost. I have never really thought it as a
problem as I have always done it in the past and often got answers
from different people.

Nobody cares if you crosspost to relevant newsgroups (ok, I shouldn't say
"nobody", but ... ). It's multiposting that's the problem.

Crosspost: Single message with multiple newsgroups in its To: field
Multipost: Multiple messages with the identical content posted separately to
multiple newsgroups

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #5
I'll bear that in mind

"Bob Barrows [MVP]" <re******@NOyah oo.SPAMcom> wrote in message
news:eE******** ******@TK2MSFTN GP10.phx.gbl...
Chris Kennedy wrote:
Sorry about the multipost. I have never really thought it as a
problem as I have always done it in the past and often got answers
from different people.
Nobody cares if you crosspost to relevant newsgroups (ok, I shouldn't say
"nobody", but ... ). It's multiposting that's the problem.

Crosspost: Single message with multiple newsgroups in its To: field
Multipost: Multiple messages with the identical content posted separately

to multiple newsgroups

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 19 '05 #6
Here is the table structure

CREATE TABLE [tblProducts] (
[productid] [int] IDENTITY (3426, 1) NOT NULL ,
[productdescript ionid] [int] NULL ,
[subgroupid] [int] NULL ,
[productcode] [nvarchar] (255) COLLATE Latin1_General_ CI_AS NULL ,
[pcksize] [nvarchar] (100) COLLATE Latin1_General_ CI_AS NULL ,
[distributordist _percent] [nvarchar] (50) COLLATE Latin1_General_ CI_AS NULL
,
[distributor_cos t_pounds] [char] (50) COLLATE Latin1_General_ CI_AS NULL ,
[description] [nvarchar] (255) COLLATE Latin1_General_ CI_AS NULL ,
[distributorpric e] [decimal](18, 2) NULL ,
[unitprice] [decimal](18, 2) NULL ,
[disc4] [decimal](18, 2) NULL ,
[disc10] [decimal](18, 2) NULL ,
[disc20] [decimal](18, 2) NULL ,
[weight] [decimal](18, 2) NULL ,
[specialoffer] [bit] NULL CONSTRAINT [DF_tblProducts_ specialoffer] DEFAULT
(0),
[add_description] [varchar] (2000) COLLATE Latin1_General_ CI_AS NULL ,
[graphic] [varchar] (200) COLLATE Latin1_General_ CI_AS NULL ,
[rank] [int] NULL ,
CONSTRAINT [PK_tblProducts] PRIMARY KEY CLUSTERED
(
[productid]
) ON [PRIMARY] ,
CONSTRAINT [FK_tblProducts_ tblProductDescr iptions] FOREIGN KEY
(
[productdescript ionid]
) REFERENCES [tblProductDescr iptions] (
[productdescript ionid]
) ON DELETE CASCADE
) ON [PRIMARY]
GO

This is an email produced as part of a shopping cart system.
In the ASP the idea is if you are logged in as one type of user you get a
distributor price, alternatively you can a different price depending on the
quantity selected. The price variable works well in the various calculations
its just when I format it or concatenate too much. The outputted string is
wrong not the underlying variable. The problem which I replicate is a the
first attempt to format price pulled from the distributor price value in the
recordset.

There is a lot of code here but.....

for each cookiekey in request.cookies ("productid" )
Key = "key" & i
productid = request.cookies ("productid")(k ey)
rsRecordset.Mov eFirst
rsRecordset.Fin d "productid =" & productid

qty = request.cookies ("qty")(key)
if isnull(rsRecord set("expirydate ")) then
expirydate = date
else
expirydate = cdate(rsRecords et("expirydate" ))
end if

if rsRecordset("sp ecialoffer") <> 0 and date < expirydate then
prodcode = rsRecordset("of fercode")
else
prodcode = rsRecordset("pr oductcode")
end if

if rsRecordset("sp ecialoffer") <> 0 and date < expirydate then
prodcode = rsRecordset("of fercode")
else
prodcode = rsRecordset("pr oductcode")
end if

if rsRecordset("sp ecialoffer") <> 0 and date < expirydate then

price = cdbl(rsRecordse t("price"))

else

if role = "2" then
'displayprice = "test" & formatcurrency( cdbl(price))
price = rsRecordset("di stributorprice" )

else
if qty < 5 then
price = csng(rsRecordse t("unitprice" ))
elseif qty > 4 and qty < 11 then
price = csng(rsRecordse t("disc4"))
elseif qty > 10 and qty < 21 then
price = csng(rsRecordse t("disc10"))
else
price = csng(rsRecordse t("disc20"))
end if

if price = 0 then
price = csng(rsRecordse t("disc10"))
end if
'response.write price
if price = 0 then
price = csng(rsRecordse t("disc4"))
'response.write price
end if

if price = 0 then
price = csng(rsRecordse t("unitprice" ))
'response.write "test"
end if

end if
end if
subtotal = cdbl(price) * cdbl(qty)
total = subtotal + total
if isnull(rsRecord set("weight")) then
weight = 0
else
weight = cdbl(rsRecordse t("weight"))
weight = weight * cdbl(qty)
end if

totalweight = weight + totalweight

HTML = HTML & "<td>" & prodcode & "</td>"
HTML = HTML & "<td>" & qty & "</td>"

'IT IS WHEN I TRY TO FORMAT THE PRICE VARIABLE IN THIS BIT

HTML = HTML & "<td>" & price & "(&euro;" & formatnumber(pr ice*rate,2) & ")"
& "</td>"
HTML = HTML & "<td>" & weight & " kg</td>"

HTML = HTML & "<td>" & formatcurrency( subtotal) & "(&euro;" &
formatnumber(su btotal*rate,2) & ")" & "</td>"
HTML = HTML & "</tr>"
weight = 0
price = 0.0
i = i + 1
next


"Aaron [SQL Server MVP]" <te*****@dnartr eb.noraa> wrote in message
news:OJ******** ********@tk2msf tngp13.phx.gbl. ..
Any ideas.


Only if you show your table structure, sample data, ASP code, and desired
results.

--
http://www.aspfaq.com/
(Reverse address to reply.)


Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6753
by: jane | last post by:
I use following code to create a Crystal Report by connecting to an access db in ASP. It works fine. Now I switch to SQL Server and it doesn't work. It seems to me there is nowhere I can add login information (userid and password). Can someone help me or point me to somewhere I can find sample code? Thanks in advance. '-- get report name reportname = "Report1.rpt"
9
4340
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side vbscript reads the database and populates a listbox on the page with the first field from each record in the recordset. This works fine. - User selects an option on the listbox and, using the OnChange, I
3
2671
by: Mick Turner | last post by:
I have connected to SQL Server database (server-side vbscript) and read some data from the tables. This works correctly. I now have the data in an array (server-side). I have to draw a line-chart based on that data, for which purpose I need to create client-side component (this works also perfectly). PROBLEM: I cannot use the server-side array for drawing the chart. Here's the code shortly:
6
23514
by: Andy Wawa | last post by:
Hi, on a simple HTML (not an ASP!)-Site I try to connect to a sql server (MS): <html> <title>Test</title> <head> <script language="javascript"> <!-- Function showForm(){
7
13444
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got the select box filling with code similar to below: <SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER> Public Sub BuildComboBox(rs, dispname, val, name, selected) 'rs = the recordset 'val = fieldname to place in the val of the option
1
3167
by: Chris | last post by:
Hi, I have jsut started to learn ASP development and have read many articles regarding which is the best to use regarding JavaScript or VBScript. All of the learning that I have done so far has been using VBScript. I have done the usual database connection and querying stuff using VBScript in my tutorials and have noticed that my code doesnt work when using Mozilla Firefox as VBScript is a Micorsoft language and
12
2261
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my office. The original code's backend is using the SQL Server 2000 and I am testing to use it on the Express edition. And I run into the following problem.
6
4920
by: avcitamer | last post by:
We upgraded our system and problem below occured, pleas help me... Windows 2003 server SP1 When I set a decimal DB field value to "123,32" (using ADODB.recordset ) updated value was ok (123.32) Windows 2003 server SP2 Now when I set a decimal DB field value to "123,32" (using ADODB.recordset ) updated value is (123.32)
2
2945
by: Rosco | last post by:
Problem: Using the sub routing below, when adding a value to another value the results eventually change from 2-decimal places to multiple decimal places. Basically, the amount stored should always only be 2 decimal places, because the values passed in are always 2 decimal places. Output from calling the sub routine multiple times. ... Running total = 329430.75 New Withheld Amount = 710.79 Running total = 330141.54
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.