June 30, 2005 at 4:46 pm
I need to be able to add a char column that is filled with dollar amounts and also account for the fact there would be decimals. For instance,
What I have :
243456
234567
What I need it to be:
2434.56
2345.67
Than I need to take those values with the decimals and add them together to make one single record. Any ideas?
June 30, 2005 at 5:18 pm
Hi could you post you DDL. Do you need to convert the data to a decimal and move it somewhere? Or do you just need the output in a decimal form?
Mike
June 30, 2005 at 5:20 pm
No Idea.
I have no idea what you mean by "Than I need to take those values with the decimals and add them together to make one single record."
Declare @Table table (pk int identity, Value1 varchar(10), Value2 varchar(10))
Insert into @Table (Value1, Value2)
values (243456, 234567)
Insert into @Table (Value1, Value2)
values (666456, 111567)
select convert(money,abs(Value1)* .01), convert(money,abs(Value2) * .01),
Convert(money,(abs(Value1) * .01) + (abs(Value2) * .01))
from @Table
Then you want to add them together and convert it to a Money datatype?
Or are these rows your talking about
243456
234567
If so how do we know what rows to add together?
Please Post a Create Table Statement, with insert statements with the data you see.
Please Read
June 30, 2005 at 6:22 pm
Basically I need a summation of the converted data to the decimal. So my final output for those two records would be
2434.56
+ 2345.67
4780.23
So the end result would be the summation of the records in decimal form.
June 30, 2005 at 6:37 pm
this should do the trick
hth Mike
drop table #tests
create table #tests
(
valone char(20),
valtwo char(20)
)
insert into #tests values('12345','23456')
insert into #tests values('22345','33456')
insert into #tests values('32345','43456')
insert into #tests values('42345','53456')
--data is stored in one var sum rows
select sum(cast(valone as money))/100 as sum_valone_rows_as_decimal from #tests
June 30, 2005 at 8:59 pm
I understand that.
But you need to tell us if 2434.56 and 2345.67 are in 2 different fields in the same row?, or if the 2 values are in the same field on 2 different rows?
Please present us with an example of what the data looks like in the table when you do a
For example
select * from myTable
Field1, Field2, Field3, Field4
1, 234354, 'I Have', 'No Clue'
2 343433, 'I Wish', 'I Did'
June 30, 2005 at 9:23 pm
Mike - did you not post something about the "right questions" just last night ?! Get a sense of deja vu yet ?!
**ASCII stupid question, get a stupid ANSI !!!**
July 1, 2005 at 1:05 am
sushila sometimes i feel like I am on a merry-go-round the scenes change but You never get anywhere.
Mike
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply