Solved

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

Posted on 2008-06-23
2
211 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 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now