Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query

Author  Topic 

chris_cs
Posting Yak Master

223 Posts

Posted - 2009-07-13 : 09:03:21
Can someone tell me why the query below doesn't return the value 5:

select (10 / 100) * 50

I get 0

As far as I can see this should work so I assume I'm doing something stupid!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-13 : 09:11:27
integer divide by integer will give you back integer so 10 / 100 will give you 0

use decimal
select (10.0 / 100) * 50



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-13 : 09:13:46
Here is the reason
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-13 : 09:15:48
DECLARE @DEC1 DECIMAL(5,1)
DECLARE @DEC2 DECIMAL(5,1)
DECLARE @DEC3 DECIMAL(5,1)

SET @DEC2 = 10
SET @DEC3 = 100
SELECT @DEC1 = @DEC2/@DEC3

SELECT @DEC1 = @DEC1*50
SELECT @DEC1


-------------------------
R..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-13 : 09:17:21
quote:
Originally posted by rajdaksha

DECLARE @DEC1 DECIMAL(5,1)
DECLARE @DEC2 DECIMAL(5,1)
DECLARE @DEC3 DECIMAL(5,1)

SET @DEC2 = 10
SET @DEC3 = 100
SELECT @DEC1 = @DEC2/@DEC3

SELECT @DEC1 = @DEC1*50
SELECT @DEC1


-------------------------
R..


No need of chaging the datatype. Refer the link

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-13 : 09:24:10
here link is not open bcoz its restricted.. i missed to read

-------------------------
R..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-13 : 09:31:25
quote:
Originally posted by rajdaksha

here link is not open bcoz its restricted.. i missed to read

-------------------------
R..


I see. How can a SQL Server related blog be blocked there?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chris_cs
Posting Yak Master

223 Posts

Posted - 2009-07-13 : 09:33:06
Thanks for the info guys!
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-13 : 09:47:34
quote:
Originally posted by madhivanan

quote:
Originally posted by rajdaksha

here link is not open bcoz its restricted.. i missed to read

-------------------------
R..


I see. How can a SQL Server related blog be blocked there?

Madhivanan

Failing to plan is Planning to fail



Posted - 07/13/2009 : 09:46:39
--------------------------------------------------------------------------------

Its blog created site right..could be GE Standards...(Client Side Validation )



-------------------------
R..
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-07-13 : 10:56:35
quote:
Originally posted by madhivanan

I see. How can a SQL Server related blog be blocked there?

Madhivanan

Failing to plan is Planning to fail



Easy. Employers block ANYTHING that has 'blog' in it. They even block Microsoft blogs. Its called lazy network admins.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-13 : 10:58:47
quote:
Originally posted by DonAtWork

quote:
Originally posted by madhivanan

I see. How can a SQL Server related blog be blocked there?

Madhivanan

Failing to plan is Planning to fail



Easy. Employers block ANYTHING that has 'blog' in it. They even block Microsoft blogs. Its called lazy network admins.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -