Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server data type problem when dividing then printing...

Posted on 2008-06-23
2
Medium Priority
?
256 Views
Last Modified: 2010-03-20
Hi,
I have the SQL statment below and the output is this:
24 / 115
0

I need the second number to be the result of the division - what am I doing wrong??

Thanks,
Tristan
--Calculate Conversion rate
		IF @CountUniqueVisits > 0 AND @CountPurchasers > 0
		BEGIN
			SET @ConversionRate = @CountPurchasers/@CountUniqueVisits
			PRINT CAST(@CountPurchasers AS VARCHAR) + ' / ' + CAST(@CountUniqueVisits AS VARCHAR)
			PRINT CONVERT(VARCHAR, @ConversionRate)
		END
 
OUTPUT:
24 / 115
0

Open in new window

0
Comment
Question by:Tristan Shortland
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 2000 total points
ID: 21845129
Hello TShortland,

What have you declared @ConversionRate as? If it is INT then as the calculation results in a value of less than 1 it will be rounded to the nearest integer - (0).

You need to declare this as numeric instead:

Declare @ConversionRate Numeric(10,3)

For example.

Regards,

TimCottee
0
 
LVL 4

Author Comment

by:Tristan Shortland
ID: 21845158
That's done the trick.
Thank you!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question