Returning a Decimal Value in a stored procedure [closed] - sql-server-2008

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to return a value that is a sum of decimal value in SQL Server 2008. I've tried using convert but it doesn't help. Here is the relevant code snips:
#ActivitySum dec (18,2) OUTPUT)
AS
SELECT
#DistinctActivities = COUNT(DISTINCT [Activities].[Activity ID]),
#Activities = COUNT([Activities].[Performer Activity ID]),
#ActivitySum = SUM(Activities.[Score])
FROM
Scenes
INNER JOIN
Every time I execute, if the sum of score has value after the decimal point, the value gets rounded to a whole number.
Any thoughts or solutions?

Related

How to sum the values of two columns and have it in a new one? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm trying to sum the values of two columns into a new one, its for analysis purpose (not creating a new column in the database)
I tried using case statement but I have no idea what is happening :
(Basically what I'm trying to say is: if the sum of the 2 columns is equal or grater than one, then count it as 1, if its 0 or null then skip and return zero)
please see the attached pictures
If you are trying to get the the sum of the two columns, you just need ton handle the null values properly.
SELECT COALESCE(speciality_count, 0) + COALESCE(Italian_count, 0)
FROM table_name

How to convert a particular column in table from hex to decimal in sql [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a query of 15 columns and one of them has a hexadecimal value, i wanted to convert it to decimal or int. How can i do it
You can also use
SELECT CONVERT(INT, *rowName*) AS Converted *rowName*;
EDIT:
CONVERT works with MS SQL
CONV(num, base, to) is for MySQL
SELECT CONV(*rowName*,16,10) AS Converted *rowName*;
use CONV()
CONV(num , from_base , to_base );
select SELECT CONV('b',16,10)'Hexadecimal to Decimal'

Convert mm/dd/yyyy string into timestamp in MySQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a column in a MySQL table where dates are stored as a mm/dd/yyyy string. I need to preserve that column as is, so I have added a new column where I want to store that date as a timestamp. What would the query look like to take column a and convert it to a timestamp and put it into the new column b?
you can use STR_TO_DATE to convert your string like
select str_to_date('02/22/2013','%m/%d/%Y');
UPDATE YourTable set newCol = str_to_date(yourOldCol,'%m/%d/%Y');

MySQL Procedures for reporting total [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Would anyone be able to help me with creating a procedure that reports the total amount paid in a specific month and specific year? Or how I would even go about creating this?
Thank you for any and all help.
I'm guessing you have a table that includes both a date column as well as an amount paid column. If that is the case, and you just want to sum the amount paid you can just use the SUM() function.
Try this:
SELECT SUM(totalAmountPaid) as totalForMonth
FROM tableName
WHERE MONTH(dateColumn) = monthYouWant AND YEAR(dateColumn) = yearYouWant
Here are date and time functions that may be useful.

MYSQL avergae and MAX number [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to query a database table. structure:
id---bid ---veh_id---user_id
There is many data, all are veh_id related. User can place bid on veh_id as many as they want and on many veih_id.
I need to find the average bid on each veh_id and also the max bid receive for that veh_id. Can this be done in one SQL query. The optimal would have the difference betwenn the average and the max number. All group by veh_id.
I don't know where to start.
If I understood correctly:
SELECT MAX(bid), AVG(bid) FROM someTable GROUP BY veh_id