473,651 Members | 2,512 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display Money Type using + and -

This may be an easy question but I've been reading for about a half
hour and experimenting without results.

I simply want the results of my query to display a specific field that
is typed "money" using + and -

The program that consumes the data expects + on positive numbers and -
on negative. I was hoping to do it in the view instead of processing
the results with the VB application that interogates the DB.

Thanks

Oct 5 '05 #1
11 2930
SQL
It should be done in VB
but you can do it like this

select case field when < 0 then '-' + convert(varchar ,field) else '+' +
convert(varchar ,field) end MoneyField from TableA

I don't know whatt you want to display for 0.00
http://sqlservercode.blogspot.com/

Oct 5 '05 #2
Why would you do this in the database? And why are you using a MONEY
column in your table?

--
David Portas
SQL Server MVP
--

Oct 5 '05 #3
Yeah.... I guess you're right - it should be done in VB.

I was trying to massage the output from the server rather than expect
each developer (who may be using different tool) from "rolling their
own" routines.

Thanks

Oct 5 '05 #4
Hi,

MONEY is the type that was used in the database table - I have no
choice with that. I was attempting to do this in the database because
I wanted to store the methods used in "massaging" this data in a
central location. It's just in a view now and maybe I would have moved
it to a parameterized stored procedure later.

So now I'll query from VB, massage the data in VB. Then in 2 years
when somebody re-writes the application using C# for an internet
application they will have to re-write the code instead of just calling
a nicely centralized routine within the database.

I honestly don't mean to offend you but why would you respond to a post
with questions like that?

Oct 5 '05 #5
No offence. I was trying to help but first I needed more information.
There could have been more than one reason why you'd want to do this -
for example you could have had a requirement to integrate the data with
an external application.

The reason I ask about MONEY in particular is that the problems with
using that datatype in calculations may sometimes be overlooked. Take a
look at the following example. Be aware of the rounding issue when you
develop calculations against the data and think carefully about the
implications before you use MONEY.

DECLA RE
@mon1 MONEY,
@mon2 MONEY,
@mon3 MONEY,
@mon4 MONEY,
@num1 DECIMAL(19,4),
@num2 DECIMAL(19,4),
@num3 DECIMAL(19,4),
@num4 DECIMAL(19,4)

SELECT
@mon1 = 100, @mon2 = 339, @mon3 = 10000,
@num1 = 100, @num2 = 339, @num3 = 10000

SET @mon4 = @mon1/@mon2*@mon3
SET @num4 = @num1/@num2*@num3

SELECT @mon4 AS money_result,
@num4 AS numeric_result

Result:

money_result numeric_result
--------------------- ---------------------
2949.0000 2949.8525

(1 row(s) affected)

--
David Portas
SQL Server MVP
--

Oct 5 '05 #6
Thanks - that is good information. I would have never guessed that -
however I may be stuck with this data type since I haven't investigate
why it's being used or where I would break something if I changed the
type to decimal.

You've convinced me though - I will never use Money for a datatype.

Cheers

Oct 5 '05 #7
Why is this the case? From the definition of MONEY in BOL I would expect
the same result.

Mike Reigler

"David Portas" <RE************ *************** *@acm.org> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
No offence. I was trying to help but first I needed more information.
There could have been more than one reason why you'd want to do this -
for example you could have had a requirement to integrate the data with
an external application.

The reason I ask about MONEY in particular is that the problems with
using that datatype in calculations may sometimes be overlooked. Take a
look at the following example. Be aware of the rounding issue when you
develop calculations against the data and think carefully about the
implications before you use MONEY.

DECLA RE
@mon1 MONEY,
@mon2 MONEY,
@mon3 MONEY,
@mon4 MONEY,
@num1 DECIMAL(19,4),
@num2 DECIMAL(19,4),
@num3 DECIMAL(19,4),
@num4 DECIMAL(19,4)

SELECT
@mon1 = 100, @mon2 = 339, @mon3 = 10000,
@num1 = 100, @num2 = 339, @num3 = 10000

SET @mon4 = @mon1/@mon2*@mon3
SET @num4 = @num1/@num2*@num3

SELECT @mon4 AS money_result,
@num4 AS numeric_result

Result:

money_result numeric_result
--------------------- ---------------------
2949.0000 2949.8525

(1 row(s) affected)

--
David Portas
SQL Server MVP
--

Oct 5 '05 #8
Nevermind. After some more digging I realized what was happening when MONEY
/ MONEY. Thanks.

Mike Reigler

"Mike Reigler" <mr******@melan ge-inc.com> wrote in message
news:11******** *****@corp.supe rnews.com...
Why is this the case? From the definition of MONEY in BOL I would expect
the same result.

Mike Reigler

"David Portas" <RE************ *************** *@acm.org> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
No offence. I was trying to help but first I needed more information.
There could have been more than one reason why you'd want to do this -
for example you could have had a requirement to integrate the data with
an external application.

The reason I ask about MONEY in particular is that the problems with
using that datatype in calculations may sometimes be overlooked. Take a
look at the following example. Be aware of the rounding issue when you
develop calculations against the data and think carefully about the
implications before you use MONEY.

DECLA RE
@mon1 MONEY,
@mon2 MONEY,
@mon3 MONEY,
@mon4 MONEY,
@num1 DECIMAL(19,4),
@num2 DECIMAL(19,4),
@num3 DECIMAL(19,4),
@num4 DECIMAL(19,4)

SELECT
@mon1 = 100, @mon2 = 339, @mon3 = 10000,
@num1 = 100, @num2 = 339, @num3 = 10000

SET @mon4 = @mon1/@mon2*@mon3
SET @num4 = @num1/@num2*@num3

SELECT @mon4 AS money_result,
@num4 AS numeric_result

Result:

money_result numeric_result
--------------------- ---------------------
2949.0000 2949.8525

(1 row(s) affected)

--
David Portas
SQL Server MVP
--


Oct 5 '05 #9
Hi:

As others have replied, the formatting should probably stay on the
front end.
If you are looking at centralizing some of the process/format, look
into an object oriented solution. This is offtopic for this newsgroup,
but you could create a money class with a formatting function that can
do the + and - formatting for you. All the developers can then use this
class instead of having to roll out their own routines. This solution
will still encapsulate the logic in one place and you don't have to
polute the database with formatting.

HTH,
BZ

Oct 5 '05 #10

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

Similar topics

24
3517
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing the code. Thank you. .. Facundo
1
2355
by: Stephane Charette | last post by:
QUICK VERSION: How do I create an index on a field of type "MONEY"? ----------------------------- LONG VERSION: I have a table with a field of type "money". I very often need to access records by the purchase price so I thought I'd create an index to help out my selects: CREATE INDEX purchasepriceidx ON mytable (purchaseprice);
3
18476
by: Ghost | last post by:
Hello. I have some problem to read Money Type Field from my database. I do so: I'm using SqlDataReader object to select some records and I have "float" type variable to store result. I write: myFloatVar = (float)mySqlDataReader; When this line executed the cast exception occurs.
10
3149
by: Sarah Smith | last post by:
Hello, I am a bit of a newbie to VB.NET, but not totally new. I took the plunge recently and decided (along with my colleagues), to try to convert/port a VB6 client/server app to .Net. (I'm not using any upgrade tools, I'm just re-writing). I have be learning/testing .net with SDI type forms and now I'm actually working on the conversion, I'm starting to worry that VB.net
4
5143
by: Jerry | last post by:
Is it possible to turn off the "$" and "," that appear in "money" formatted columns so I can dump the table in a numeric format? The man page hints that lc_monetary controls the formatting but I cannot find any clues on what to do... Apparently money cannot be cast to anything. I don't think it will be hard to write a custom tcl/perl script that takes a "copy checks to...." command to do the task
1
1812
by: bigmaddaz | last post by:
Ok im designing an application for working out compount interest. The user starts the page, 3 prompts appear, one asking for money invested, next asking for rate of interest, and last one asking for length of time money invested. All what now displays on the page is simple a calculate button. When the user clicks this calculate button, a new window opens, showing in table form what the user inputted and the actual calculation. I have all...
15
4055
by: soni2926 | last post by:
Hi, I have the following: float.Parse(myproduct.Price.Value.ToString()); myproduct.Price.Value.ToString() returns $24.00 (with the $) Is there anyway to do the above cast, I know the float.Parse(...) doesn't like the $, as i keep getting an invalid cast exception, is there anyway to get this to work? Do i just need to strip out the $ with substring, or is there a better way to cast it?
0
1167
by: gggram2000 | last post by:
Hi there, I'm using microsoft visual studio 2005, with c# code. I recently downloaded GemBox which is a spreadsheet for excel. I can pass parameters through textboxes, comboboxes, labels...etc and display it on cells in excell. But now Im calling parameters directly from the database...I would like to know how to display it in excel...Here is part of the code I'm working on: (How can I make it work?) ExcelFile ef = new ExcelFile(); ...
3
3437
by: Stephan Diehl | last post by:
Hi lazyweb, I'm wondering, if there is a usable money data type for python available. A quick search in pypi and google didn't convey anything, even though the decimal data type seemed to be planned as a money data type originaly. Thanks for any pointers Stephan
0
8275
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
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8465
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
8579
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
6158
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
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
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...
1
2699
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
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.