AVG Does Not Return A Decimal Value

Apr 30, 2008



Hi !

I'm doing something like :


SELECT AVG(timeConsumed) as average_time_consumed

FROM table1 where ...


The value return is 42, however if i do this using a calculator the result is 42,39583

How can i get the decimal part ?

I have tried this : AVG(timeConsumed)*1.0, but the value returned is 42.0




View 1 Replies


ADVERTISEMENT

Expression Does Not Return Decimal Value!

Nov 29, 2007

Hello,
Below statement in tsql returns int value (0).

SELECT 5/10

How to force it to return decimal value (0.5)?
I tried following but it did not help me
1) SELECT Convert(numeric(7,2),5/10)
2) Declare @Var1 numeric(7,2)
SET @Var1 = SELECT Convert(numeric(7,2),5/10)
SELECT @Var1

Thanks.

View 3 Replies View Related

Set Up Query To Return Only 2 Decimal Places?

Mar 3, 2005

Hi. I have a query that returns several averages and percentages. Is there some way to set up the query so the results only go to 2 decimal places? Here is a sample of the query I am using:
Code:

$query = "SELECT COUNT(deal_id), SUM(vs), SUM(vs)/COUNT(deal_id)*100, AVG(fin) FROM sales GROUP BY salesperson";



It works great,except the results are several decimal places long, and I need it to be only 2.

Any help appreciated.
Cori

Never mind, I found it muhself....

FORMAT(AVG(fin),2) works perfectly!!

View 5 Replies View Related

DateDiff - Return Months In Decimal?

Jun 24, 2004

I've been trying to create a function that returns the difference, in months, between two dates. The DateDiff function (m) returns an integer, but I really need a decimal. I could return the days instead, but it would be difficult to figure out how the number of months from this, especially when the dates span multiple years and I need to adjust for leap year. Does anyone know of a resource that might have a solution for this?

Thanks,
Rob

View 8 Replies View Related

Execute SQl Task Return Decimal Type Result

Dec 3, 2007



I am trying to have an Excecute SQL Task return a single row result set executed on SQL Server 2005.


The query in the Execute SQL Task is:
select 735.234, 2454.123

I get a conversion error when trying to assign to SSIS variables of type Double.
I have nothing configured in the "Parameter Mapping" tab.
I have the two SSIS Double variables mapped to the Tesult Name 0 and 1 in the "Result Set" tab

I don't want to use a for loop enumerator since there is a single row returned.

I simply want to assign these two values to SSIS Double variables (double is the closest match)


I can't even hack this by converting the decimals as string and then using DirectCast to convert them to Double.

Thanks for the help

View 1 Replies View Related

Legacy Database Uses Decimal Data Types.--&> AutomobileTypeId (PK, Decimal(10,0), Not Null) Why Not Integers Instead ?

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

Data Type With Decimal Point For Decimal Values But Not For Whole Integers

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

Cast Or Convert Nvarchar With Comma As Decimal Separator To Decimal

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

Converting (casting) From Decimal(24,4) To Decimal(21,4) Data Type Problem

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

How Can I Use The Decimal Comma Instead Of Decimal Point For Numbers In Jet Engine?

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

Converting Decimal To String W/O Decimal Point

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

Converting Decimal Point To Decimal Comma

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

Decimal Limited To 4 Digits To Right Of Decimal?

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

Packed Decimal To Decimal Conversion

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

Return Error Code (return Value) From A Stored Procedure Using A Sql Task

Feb 12, 2008


I have a package that I have been attempting to return a error code after the stored procedure executes, otherwise the package works great.

I call the stored procedure from a Execute SQL Task (execute Marketing_extract_history_load_test ?, ? OUTPUT)
The sql task rowset is set to NONE. It is a OLEB connection.

I have two parameters mapped:

tablename input varchar 0 (this variable is set earlier in a foreach loop) ADO.
returnvalue output long 1

I set the breakpoint and see the values change, but I have a OnFailure conditon set if it returns a failure. The failure is ignored and the package completes. No quite what I wanted.

The first part of the sp is below and I set the value @i and return.


CREATE procedure [dbo].[Marketing_extract_history_load_TEST]

@table_name varchar(200),

@i int output

as

Why is it not capturing and setting the error and execute my OnFailure code? I have tried setting one of my parameter mappings to returnvalue with no success.

View 2 Replies View Related

How To Return SqlDataReader And Return Value (page Count) From SPROC

Jan 2, 2006

This is my function, it returns SQLDataReader to DATALIST control. How
to return page number with the SQLDataReader set ? sql server 2005,
asp.net 2.0

    Function get_all_events() As SqlDataReader
        Dim myConnection As New
SqlConnection(ConfigurationManager.AppSettings("..........."))
        Dim myCommand As New SqlCommand("EVENTS_LIST_BY_REGION_ALL", myConnection)
        myCommand.CommandType = CommandType.StoredProcedure

        Dim parameterState As New SqlParameter("@State", SqlDbType.VarChar, 2)
        parameterState.Value = Request.Params("State")
        myCommand.Parameters.Add(parameterState)

        Dim parameterPagesize As New SqlParameter("@pagesize", SqlDbType.Int, 4)
        parameterPagesize.Value = 20
        myCommand.Parameters.Add(parameterPagesize)

        Dim parameterPagenum As New SqlParameter("@pageNum", SqlDbType.Int, 4)
        parameterPagenum.Value = pn1.SelectedPage
        myCommand.Parameters.Add(parameterPagenum)

        Dim parameterPageCount As New SqlParameter("@pagecount", SqlDbType.Int, 4)
        parameterPageCount.Direction = ParameterDirection.ReturnValue
        myCommand.Parameters.Add(parameterPageCount)

        myConnection.Open()
        'myCommand.ExecuteReader(CommandBehavior.CloseConnection)
        'pages = CType(myCommand.Parameters("@pagecount").Value, Integer)
        Return myCommand.ExecuteReader(CommandBehavior.CloseConnection)
    End Function

Variable Pages is global integer.

This is what i am calling
        DataList1.DataSource = get_all_events()
        DataList1.DataBind()

How to return records and also the return value of pagecount ? i tried many options, nothing work. Please help !!. I am struck

View 3 Replies View Related

'Return' Statement In A Function,Get,or Operator Must Return A Value....Question

Aug 28, 2007


I'm a Reporting Services New-Be.

I'm trying to create a report that's based on a SQL-2005 Stored Procedure.

I added the Report Designer, a Report dataset ( based on a shared datasource).

When I try to build the project in BIDS, I get an error. The error occurs three times, once for each parameter on the stored procedure.

I'll only reproduce one instance of the error for the sake of brevity.

[rsCompilerErrorInExpression] The Value expression for the query parameter 'UserID' contains an error : [BC30654] 'Return' statement in a Function, Get, or Operator must return a value.

I've searched on this error and it looks like it's a Visual Basic error :

http://msdn2.microsoft.com/en-us/library/8x403818(VS.80).aspx

My guess is that BIDS is creating some VB code behind the scenes for the report.

I can't find any other information that seems to fit this error.

The other reports in the BIDS project built successfully before I added this report, so it must be something specific to the report.

BTW, the Stored Procedure this report is based on a global temp table. The other reports do not use temp tables.

Can anyone help ?

Thanks,

View 5 Replies View Related

Using Output Clause And Return Timestamp And Return Value

Oct 28, 2006

I am trying to bring my stored proc's into the 21st century with try catch and the output clause. In the past I have returned info like the new timestamp, the new identity (if an insert sproc), username with output params and a return value as well. I have checked if error is a concurrency violation(I check if @@rowcount is 0 and if so my return value is a special number.)

I have used the old goto method for trapping errors committing or rolling back the transaction.

Now I want to use the try,catch with transactions. This is easy enough but how do I do what I had done before?

I get an error returning the new timestamp in the Output clause (tstamp is my timestamp field -- so I am using inserted.tstamp).

Plus how do I check for concerrency error. Is it the same as before and if so would the check of @@rowcount be in the catch section?

So how to return timestamp and a return value and how to check for concurrency all in the try/catch.

by the way I read that you could not return an identity in the output clause but I had no problem.

Thanks for help on this

SM haig

View 5 Replies View Related

T-SQL ROUND(decimal, Int) Vs C# Round(Decimal, Int32)

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

Why SP Return SQLException When No Data Return ?

Jul 24, 2006

hi, good day,

i have using BCP to output SP return data into txt file, however, when it return nothing , it give SQLException like "no rows affected" , i have try to find out the solution , which include put "SET NOCOUNT ON" command before select statement, but it doesn't help :(

anyone know how to handle the problem when SP return no data ?

thanks in advance

View 1 Replies View Related

Transact SQL :: Return Set Of Values From SELECT As One Of Return Values From Stored Procedure

Aug 19, 2015

I have a stored procedure that selects the unique Name of an item from one table. 

SELECT DISTINCT ChainName from Chains

For each ChainName, there exists 0 or more StoreNames in the Stores. I want to return the result of this select as the second field in each row of the result set.

SELECT DISTINCT StoreName FROM Stores WHERE Stores.ChainName = ChainName

Each row of the result set returned by the stored procedure would contain:

ChainName, Array of StoreNames (or comma separated strings or whatever)

How can I code a stored procedure to do this?

View 17 Replies View Related

Decimal To Hex

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

Need Help With Avg And Decimal

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

Using Decimal As A Key

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

Decimal

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

SqlMoney Vs. Decimal

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

Decimal Problem

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

Cannot Convert To Decimal

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

2 Decimal Places On Sql AVG ()

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

Decimal Length

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

Inserting A Decimal

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

Inserting A Decimal - HELP

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

My Decimal Value Is Being Rounded Of When It Gets To The Db

Jan 28, 2004

Hi

I'm inserting a decimal value into my db but it keeps round it of to a single figure. Its the result of time between two times. ie between 1:00 and 2:30 equals 2.5. But it ends up as 2 in the db even though the db field is also decimal. I know by looking at the watch in the bugger that its actually a decimal value just prior to insertion which only leads me to suspect that sql server is doing the rounding of, maybe this is the default behaviour but i need it to store the values as decimal.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved