May 7, 2009 at 10:29 pm
karthikeyan (5/7/2009)
Sorry! I am not getting you...
Try again.
Here is a shorter version of your code, easier to get:
DECLARE @Fixed2 decimal(8,4)
SET @Fixed2 = 12121.03
_____________
Code for TallyGenerator
May 7, 2009 at 10:36 pm
karthikeyan (5/7/2009)
Lynn,Yes.It will work.. But I have more than one row in the table,so i can't use local variable here, becuase it lead us to use 'LOOP'.
Really, and you know this how? I suggest you give it a try before you dismiss it out of hand. I think you will be quite surprised to find it will work just fine, even if you have a 1,000,000 row table.
I'd even bet money on it.
AND it doesn't require a LOOP!!
May 7, 2009 at 10:41 pm
karthikeyan (5/7/2009)
Lynn Pettis (5/6/2009)
karthikeyan (5/6/2009)
I tried the below codeDECLARE @Fixed1 decimal(8,4), @Fixed2 decimal(8,4), @Fixed3 decimal(16,8);
SET @Fixed1 = 5444.32;
SET @Fixed2 = 12121.03; <-- Problem is here. decimal(8,4) means you only have room for 4 positions to the left of the . as well
SET @Fixed3 = @Fixed1 * @Fixed2;
SELECT @Fixed3
I got the truncation error.
To multiply two decimal(8,4) values, we need decimal(16,8) to sotre the resut. Right?
If yes, then why it is throwing the error message?
select 5444.32*12121.03
gave the correct result.
if i multiply two decimal(16,8) values, then how much space i need? decimal(32,16). Correct?
See the bold comment above.
Sorry! I am not getting you...
select 5444.32*12121.03
output:
65990766.0496
then why i need to worry about the digits after the decimal point.
To multiply two decimal(8,4) values, we need decimal(16,8) to store the resut.
Is this right?
Again, you must be kidding me. A variable or column defined decimal(8,4) means you have 8 digits total, four of them AFTER (or to the right) of the decimal point. This leaves you 4 digits to the LEFT of the decimal point as well. 12121.03 WILL NOT FIT in this column or variable.
I hope I have clarified this well enough, but if not please take the time to read Books On-Line. It will tell you the same thing.
May 11, 2009 at 4:25 am
Lynn Pettis (5/7/2009)
karthikeyan (5/7/2009)
Lynn Pettis (5/6/2009)
karthikeyan (5/6/2009)
I tried the below codeDECLARE @Fixed1 decimal(8,4), @Fixed2 decimal(8,4), @Fixed3 decimal(16,8);
SET @Fixed1 = 5444.32;
SET @Fixed2 = 12121.03; <-- Problem is here. decimal(8,4) means you only have room for 4 positions to the left of the . as well
SET @Fixed3 = @Fixed1 * @Fixed2;
SELECT @Fixed3
I got the truncation error.
To multiply two decimal(8,4) values, we need decimal(16,8) to sotre the resut. Right?
If yes, then why it is throwing the error message?
select 5444.32*12121.03
gave the correct result.
if i multiply two decimal(16,8) values, then how much space i need? decimal(32,16). Correct?
See the bold comment above.
Sorry! I am not getting you...
select 5444.32*12121.03
output:
65990766.0496
then why i need to worry about the digits after the decimal point.
To multiply two decimal(8,4) values, we need decimal(16,8) to store the resut.
Is this right?
Again, you must be kidding me. A variable or column defined decimal(8,4) means you have 8 digits total, four of them AFTER (or to the right) of the decimal point. This leaves you 4 digits to the LEFT of the decimal point as well. 12121.03 WILL NOT FIT in this column or variable.
I hope I have clarified this well enough, but if not please take the time to read Books On-Line. It will tell you the same thing.
oops...i got it now....Thanks Lynn.
karthik
May 11, 2009 at 4:26 am
Sergiy (5/7/2009)
karthikeyan (5/7/2009)
Sorry! I am not getting you...Try again.
Here is a shorter version of your code, easier to get:
DECLARE @Fixed2 decimal(8,4)
SET @Fixed2 = 12121.03
Thanks Sergiy! I have identifed my mistake...i mean where i did the mistake....
karthik
May 11, 2009 at 4:30 am
Lynn Pettis (5/7/2009)
karthikeyan (5/7/2009)
Lynn,Yes.It will work.. But I have more than one row in the table,so i can't use local variable here, becuase it lead us to use 'LOOP'.
Really, and you know this how? I suggest you give it a try before you dismiss it out of hand. I think you will be quite surprised to find it will work just fine, even if you have a 1,000,000 row table.
I'd even bet money on it.
AND it doesn't require a LOOP!!
Ummm....Ok...Give me some time....I will try and get back to you...
I'd even bet money on it.
Just kidding...how much you bet? 😛
I am not expecting too much.:-P
karthik
May 11, 2009 at 4:51 am
karthikeyan (5/11/2009)
I'd even bet money on it.
Just kidding...how much you bet? 😛
I am not expecting too much.:-P
When 2 are betting one of them is a fool, another one is a rascal.
Rascal because one knows the outcome. For sure.
And can bet any money. More is better.
😉
_____________
Code for TallyGenerator
Viewing 7 posts - 16 through 22 (of 22 total)
You must be logged in to reply to this topic. Login to reply