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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help wiht replace

Author  Topic 

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2007-09-28 : 04:08:24
Hi.
Can you tell me what this do?Difference?
replace(cast(cast(SUM(cc.NETPREMIUM/isnull(r.fixing,1)) as decimal(10,2)) as varchar) ,'.',',') as NETPREMIUMEURO


AND

replace(cast(cast(SUM(cc.NETPREMIUM) as decimal(10,2)) as varchar) ,'.',',') as NETPREMIUM

r is a table with currencyrates
I try to figure it out. I think if the NETPREMIUM is null then it replace it with a currencyrate. Am i right?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-28 : 04:12:20
No.
In first statement NetPremium is divided by r.Fixing and the resulting output after converted to varchar, REPLACE() function
replaces deimal point character with comma character.

Second statement is similar to first except that NetPremium is not divided by Fixing value.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-28 : 04:18:34
"divided by r.Fixing"

But rather scarily if r.Fixing IS NULL it will divide by ONE instead, which will a) silently hide the NULL value and b) I'm struggling to believe that that will be a credible value for anything, but it all depends on the data and the application of course.

Lots of formatting stuff going on that would be better done in the Presentation Layer

Kristen
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2007-09-28 : 04:21:08
Thank you.
And the "isnull"? isnull(r.fixing,1))?
the bifference between "/isnull(r.fixing,1))"
and "/(r.fixing,1)" ?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-28 : 04:24:37
"And the "isnull"? isnull(r.fixing,1))?"

IsNull(A, B)

returns A if it is NOT null, otherwise it returns B.

Kristen
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2007-09-28 : 04:25:11
Oh sorry you answered.
So am i guessing that the second replace is most likely to be correct?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-28 : 04:27:08
Sorry, which one is the "second replace" you are referring to?
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2007-09-28 : 04:29:00
replace(cast(cast(SUM(cc.NETPREMIUM) as decimal(10,2)) as varchar) ,'.',',') as NETPREMIUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-28 : 04:44:14
quote:
Originally posted by sapator

replace(cast(cast(SUM(cc.NETPREMIUM) as decimal(10,2)) as varchar) ,'.',',') as NETPREMIUM


It replaces dot with comma

Read about Replace function in sql server help file

Madhivanan

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

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2007-09-28 : 04:52:28
Yes i ment that the whole function is most likely to be accurate because it returns the exact results.
Go to Top of Page
   

- Advertisement -