Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

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

Posted on 2008-06-23
Medium Priority
252 Views
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
``````
0
Question by:Tristan Shortland
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 43

Accepted Solution

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

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

## Featured Post

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
###### Suggested Courses
Course of the Month9 days, 3 hours left to enroll