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
2
Medium Priority
?
252 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
[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
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.

721 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