Decimal/smallmoney
Apr 27, 2007
Hello all,
I have two values (1.0 and 0.50 that need to be saved into SQL Server 2005 as numeric values. My issue is that when I try to save 0.5 to the table it is rounded up to 1.0. I checked the Stored Procedures and it looks good there. I tried the datatypes decimal (2, 1) and small money but both cause the value to round. Can anyone help me save the value as 0.5 to the table?
Thanks in advance!
View 3 Replies
ADVERTISEMENT
Aug 12, 2000
Hello all...
I am new to SQL 7, and am having trouble with the money and smallmoney data-types. When I pull data from these columns, it has four decimal places, and I need only two (four is screwing the perl code up). What do I do now?
All help much appreciated!
View 2 Replies
View Related
Aug 27, 2004
Could someone explain to me what the best practices are for using these three data types? (i.e. when to use them). I thought this would be a simple answer to find, but after looking through books on line, and this forum, I have still not found the answer. Can anyone help?
View 1 Replies
View Related
Jan 2, 2008
I have a table for products and the price field is smallmoney data type. When I view the data stored it shows it with millionths. How do I get it to store only hundredths?
View 2 Replies
View Related
Mar 15, 2008
What is the difference between money and smallmoney, and is there a way to format these?
View 3 Replies
View Related
Jul 18, 2003
using SQL2000, table has a field defined as 'smallmoney'. This is being populated from a text file that has two digits after the decimal -> 56.50
I was trying to use cast and convert going in but no luck, as near as I can determine they only work on output.
So the question is : how can I get string data into smallmoney. Otherwise I have to redefined the field as a varchar or decimal
Comments?
Thanks
RK
View 14 Replies
View Related
Mar 25, 2007
whenever i add values in my price column, it automatically put 4 decimal places. how will i limit to 2 decimal places of this smallmoney datatype?
View 4 Replies
View Related
Jul 3, 2007
Using the following script...
create table a
( policy_id int not null,
amount smallmoney not null);
insert a values (1, 100.0);
select policy_id, sum(amount) sum_amount
into b
from a
group by policy_id;
Why is the datatype, of column sum_amount in table b, money rather than smallmoney?
View 1 Replies
View Related
Feb 15, 2004
Hello,
I am having a problem with a stored procedure and inserting money value into a smallmoney field. I have tried a few different lines but still get errors. This is a sample of the code below and the problem is with the MenuCost and converting a string to smallmoney. I am not having any luck with. Thanks inadvance for any advice.
Gary
Dim MenuName As String = txtName.Text
Dim MenuDescription As String = txtDescription.Text
Dim MenuCatId As String = DropDownList2.DataValueField
Dim MenuTypeId As String = DropDownList1.DataValueField
Dim MenuCost As String = txtCost.Text
Dim ConnectionString As String = fdfadsfdsfasdfsdfsdf
Dim CommandText3 As String = "ins_MenuItem"
Dim myConnection3 As New SqlConnection(ConnectionString)
Dim myCommand3 As New SqlCommand(CommandText3, myConnection3)
Dim workParam As New SqlParameter()
myCommand3.CommandType = CommandType.StoredProcedure
With myCommand3.Parameters
.Add("@MenuName", SqlDbType.Varchar, 150, MenuName)
.Add("@MenuDescription", SqlDbType.Text, MenuDescription)
.Add("@MenuCatId", SqlDbType.Int, MenuCatId)
.Add("@MenuTypeId", SqlDbType.Int, MenuTypeId)
'.Add("@MenuCost", SqlDbType.SmallMoney,4,System.Data.SqlTypes.SqlMoney.Parse(MenuCost))
'.Add("@MenuCost", SqlDbType.SmallMoney,4, Convert(MenuCost AS Varchar))
'.Add("@Amount", SqlDbType.SmallMoney,4,System.Data.SqlTypes.SqlMoney.Parse(Amount))
'.Add("@MenuCost", SqlDbType.SmallMoney,4,System.Data.SqlTypes.SqlMoney.Parse(MenuCost))
End With
myConnection3.Open()
View 2 Replies
View Related
Jul 21, 2003
the placeholder approach works nicely with an insert statement and I've tried it with an update statement but keep getting an error. This is the current code:
Var1 = strArray(1)
Var2 = strArray(2)
Var3 = (strArray(3)
Cmd.CommandText = "UPDATE WBS.dbo.pludec38 SET PLU = ?, SET Dscrpt1 = ?, SET Price = ?"
Cmd.Parameters.Refresh
Cmd.Parameters(0) = Var1
Cmd.Parameters(1) = Var2
Cmd.Parameters(2) = Var3
Cmd.Execute
The error occurs at or near the refresh stmt. What am I doing that is causing this? And what is the difference between this and the insert. The insert uses the parameters block without choking.
Thanks
RK
View 11 Replies
View Related
Oct 11, 2006
Hi
My ticket engine stores values in varchar. The sql db-field that
corresponds was created as smallmoney.
The below statement works for conversion of "leavedays" if the given
value is entered without any decimal places (E.G. 4)
As soon as a user enters a value that includes decimal places (E.G.
4.5) the conversion will not work. In this case the value 4.5 is
rounded to 5.
What do i have to do to convert the value as it is entered by the user?
Thanks in advance
t.
Statement:
INSERT INTO leavereq (mitarbeiter, startdate, enddate, leavedays,
remainingdays, approvedby, approvedon) SELECT {0} , convert(datetime,
{1}) , convert(datetime, {2}), convert(numeric, {3}), convert(numeric,
{4}),{5}, getdate()
DDL for concerned database:
CREATE TABLE [dbo].[leavereq] (
[mitarbeiter] char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[startdate] datetime NULL,
[enddate] datetime NULL,
[leavedays] smallmoney NULL,
[remainingdays] smallmoney NULL,
[approvedon] datetime NULL,
[approvedby] char(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
ON [PRIMARY]
GO
View 3 Replies
View Related
Jun 5, 2007
what i understand if if the data field is integer or money, not string, then i need to do a convert(datatype, value) in the insert but how come its still not working INSERT INTO [Product] ([Title], [Description], [Processor], [Motherboard], [Chipset], [RAM], [HDD], [OpticalDrive], [Graphics], [Sound], [Speakers], [LCD], [Keyboard], [Mouse], [Chassis], [PSU], [Price]) VALUES (@Title, @Description, @Processor, @Motherboard, @Chipset, @RAM, @HDD, @OpticalDrive, @Graphics, @Sound, @Speakers, @LCD, @Keyboard, @Mouse, @Chassis, @PSU, convert(smallmoney, @Price))
View 1 Replies
View Related
Sep 26, 2007
I am working with a legacy SQL server database from SQL Server 2000. I noticed that in some places that they use decimal data types, that I would normally think they should be using integer data types. Why is this does anyone know?
Example: AutomobileTypeId (PK, decimal(10,0), not null)
View 5 Replies
View Related
Dec 8, 2013
I am creating a table on SQL Server. One of the columns in this new table contains whole integer as wells as decimal values (i.e. 4500 0.9876). I currently have this column defined as Decimal(12,4). This adds 4 digits after the decimal point to the whole integers. Is there a data type that will have the decimal point only for decimal values and no decimal point for the whole integers?
View 2 Replies
View Related
Apr 29, 2008
Hello.
My database stores the decimals in Spanish format; "," (comma) as decimal separator.
I need to convert decimal nvarchar values (with comma as decimal separator) as a decimal or int.
Any Case using CAST or CONVERT, For Decimal or Int gives me the following error:
Error converting data type varchar to numeric
Any knows how to resolve.
Or any knows any parameter or similar, to indicate to the Cast or Convert, that the decimal separator is a comma instead a dot.
View 5 Replies
View Related
Jul 24, 2006
Hello!
I would like to cast (convert) data type decimal(24,4) to
decimal(21,4). I could not do this using standard casting function
CAST(@variable as decimal(21,4)) or CONVERT(decimal(21,4),@variable)
because of the following error: "Arithmetic overflow error converting
numeric to data type numeric." Is that because of possible loss of the
value?
Thanks for giving me any advice,
Ziga
View 6 Replies
View Related
Sep 19, 2007
I wanted to convert a dataset from vb.net (2.0) to an .XLS file, by MS Jet. My national standard is using decimal commas, not decimal points for numbers signing the beginning of decimal places.
But the MS Jet Engine uses decimal point,in default. Therefore, in the Excel file only string formatted cells can welcome this data, not number formatted.
How can I solve or get around this problem? (with jet if it possible)
iviczl
View 4 Replies
View Related
Jul 23, 2005
I'd like to convert a Decimal value into a string so that the entireoriginal value and length remains intact but there is no decimal point.For example, the decimal value 6.250 is selected as 06250.Can this be done?
View 6 Replies
View Related
Nov 30, 2007
Hi all,
I am designing some reports for a German branch of my company and need to replace decimal point with a comma and the thousand comma seperator with a decimal point.
e.g.
‚¬1,500,123.00 to ‚¬1.500.123,00
Is there a property that I can change in the report designer to allow this to happen or is this something I need to convert in a Stored Proc.
Any help would be much appreciated
Thanks!
View 5 Replies
View Related
Jun 18, 2007
I need to store decimal values: decimal(20,15) in my SQL Server 2005 database.
I load data from flat file, convert it using Data Conversion Task to decimal(with scale: 15) and try to save it using OLE DB Destination.
It works fine for 4 digits after the decimal (like 1.1234), but always failes for more than 4 digits (1.12345).
Is the decimal limited to scale 4 ???
Thank you for your help!
Anna
View 3 Replies
View Related
Jun 4, 2007
Hi,
I am having a file in which amount fields are given in a Packed Decimal format. Can anyone suggest me how I can read this data element from the file and convert it into SQL decimal datatype.
File is a fixed length. All the amount fields are given in Packed Decimal Format and rest of the fields are given in text format.
How can i identify and convert only those packed decimals using SQL/.Net.
Example : a row in a file that has some packed decimals
158203508540188236252EUR20BZK0030 Å“&
20060715 0001010100010101
Please help!
Thanks
Mirudhu
View 4 Replies
View Related
Jan 30, 2006
Anybody noticed that SQL Server rounds up if the value is half waybetween two rounded values, but C#'s Decimal.Round(Decimal,Int32)rounds to nearest even number?[color=blue]>From MSDN: "When d is exactly halfway between two rounded values, the[/color]result is the rounded value that has an even digit in the far rightdecimal position. For example, when rounded to two decimals, the value2.345 becomes 2.34 and the value 2.355 becomes 2.36. This process isknown as rounding toward even, or rounding to nearest."I perform the same calculation sometimes on the web server in C# andsometimes at the database in T-SQL, but want to get the same resultfrom both calculations. Could anybody offer any strategies for dealingwith this?Thanks ~ Matt
View 3 Replies
View Related
Jul 8, 2004
Is there a way to create a SP or UDF that converts a decimal number to hexidecimal notation?
View 3 Replies
View Related
Jul 23, 2005
i am having trouble the with the line below:SELECT AVG(CAST(RATE1 AS Decimal(9, 2))) AS Expr1i am trying to do an average on the column "rate1" and want only 2decimal points but the syntax i wrote doesn't do it. is theresomething i am missing or doing wrong?when i run the above syntax i get 7.246428 and i need it to be 7.2 iknow this is possible in SQL but for some reason cant figure it out.Any help would be greatly appreciated.thanks
View 2 Replies
View Related
Jul 11, 2006
Is there any disadvantages of using Decimal type as a primary key? Ifso, are there other data types that can hold large numbers (more thanan int can hold: 13 digits or so) and perform better as a Key field?Thanks.
View 3 Replies
View Related
Mar 19, 2008
I imported some feilds from a text file. Most of which i set to varchar. However, I want one of the feilds to have 2 decimal places.
I tried changing it in the table design after the import and nothing changed.
Then i tried re-writing the query for insertiing the values, where i changed varchar(11) to numeric (11,2) but i got an error. "Error converting data type nvarchar to numeric."
Any suggestions on resolving this glitch ??
View 8 Replies
View Related
Jul 17, 2006
I just created a new table in my database. One of the fields in that table has a data type of money. Would my C# code be better off referring to this field as SqlMoney or as a decimal and why?
Would I be better off altering the field in the table so that it has a data type of decimal?
Thanks
View 12 Replies
View Related
Dec 18, 2006
Hi guys,I've got a table with one of the columns 'ConversionRate' declared as decimal. The value for this column is defined as 1.45. In my vb file, I tried to retrieve the value using a SqlParameter as shown below:myConversionRate = Me.SqlCommand.Parameters.Add(Sql.StoredProcParameter.ConversionRate, SqlDbType.Decimal)myConversionRate.Direction = ParameterDirection.Output which will access the following query in my stored proc: ALTER PROCEDURE dbo.Charge
@PConversionRate DECIMAL = 0 OUTPUT
AS
SELECT @PConversionRate = ConversionRate,
FROM TblCharge
For some reasons, the value returned is always 1 instead of 1.45. Anyone experienced this problem before and knows how to resolve it? Thanks in advance.
View 7 Replies
View Related
Apr 17, 2007
I have a money field in SQL that when i try and get the sum of it i cannot convert it to decimal. This was working now its not, and nothing was changed.Any reason for the error? DECLARE @TEST decimal(10,2)SET @Test = (SELECT SUM(INV_Net) FROM abc.dbo.iSplit_Details WHERE LoanID='0000010604')Print @TestRETURNS: 160471.24----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Specified cast is not valid. Description:
An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and
where it originated in the code. Exception Details:
System.InvalidCastException: Specified cast is not valid.Source
Error:
Line 3576: // CURRENT TOTALLine 3577: cmd.CommandText = "SELECT SUM(INV_Net) FROM abc.dbo.iSplit_Details WHERE LoanID=@LoanID";Line 3578: decimal split_currentamt = ((decimal)cmd.ExecuteScalar());
View 6 Replies
View Related
May 31, 2007
Hi,
I am trying to get my string to 2 decimal places...
Here is the code:string sumSQL = "SELECT CONVERT (float,sum(callTime)/count(callTime)) as CAVG FROM leads where agent = '" + agent + "' and " + dates.Text;
SqlCommand sumCMD = new SqlCommand(sumSQL, conn2);
object null1 = sumCMD.ExecuteScalar();if (null1 != null)
{string avgS = sumCMD.ExecuteScalar().ToString();Response.Write(avgS + "<br>" + "</td></tr><tr>");
}
Any Help appreciated...
Doug
View 1 Replies
View Related
Feb 6, 2008
Hi all - am in a bit of a quandry over this one!My application is all up and running - it's an despact & accounts app - I've missed one thing though - the ability to deal with half pennies (or half cents for those of you over the pond ;))
All of my tables are set up as decimal (19,2) along with all the params in my stored procs (a lot!). Is there an easy way to change all of these in 1 swoop?
Thanks in advance,
Stephen.
View 1 Replies
View Related
Apr 12, 2008
Hi i have a insert stored procedure, which i need to insert a label.text which is 12.99
the problem i have is that it is inserting as 13.00 any ideas what i need to do??Dim Price As Decimal = CostLabel.Text then i am inserting with this param....
command113.Parameters.Add("@Cost", SqlDbType.Decimal).Value = Price
View 4 Replies
View Related
Dec 23, 2003
Im trying to insert a decimal into SQL 2000 using a stored procedure. I can successfully insert it using a direct T-SQL statement inside the code, but I cant insert it correctly when calling for a stored procedure.
For instance 12.5 will insert as 12.
Here is my SQL Parameter code:
[code]
MyCommand.Parameters.Add(New SqlParameter("@Num", SqlDbType.Decimal))
MyCommand.Parameters("@Num").Precision = 5
MyCommand.Parameters("@Num").Scale = 2
MyCommand.Parameters("@Num").Value = Convert.ToDecimal(TextBox1.Text)
[/code]
I also declared @Num to be a decimal in my Stored Procedure.
As you can see I give the Parameter more than enough detail about the data type as well as convert the textbox value to a decimal, but it still rounds the value to an integer like data.
Again using a direct T-SQL statement inside the code works OK, but the stored procedure will not.
ANyone got any ideas why this is happening.
View 1 Replies
View Related