SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 ASP.NET
 operator overrdng
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dehseth
Starting Member

Turkey
18 Posts

Posted - 12/29/2006 :  07:09:30  Show Profile  Reply with Quote
is there any way to override + operator for int type?

harsh_athalye
Flowing Fount of Yak Knowledge

India
5512 Posts

Posted - 12/29/2006 :  08:14:05  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Do you think posting irrelevant question in mutiple forums will make it any good?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76921

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

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 12/29/2006 :  08:35:40  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
dehseth -- Why the heck would you want to do that??? And what does that have to do with SQL Server ?

- Jeff
Go to Top of Page

dehseth
Starting Member

Turkey
18 Posts

Posted - 12/29/2006 :  08:59:19  Show Profile  Reply with Quote
quote:
Originally posted by jsmith8858

dehseth -- Why the heck would you want to do that??? And what does that have to do with SQL Server ?

- Jeff



i need to override divsion operator / because of division by zero.
i just wanna put 0 if there's division of zero.
an example:
@a = @b / @c + 20
if @c is 0 i want to see 20 in @a.

why? cause i need to. if u know plz help
Go to Top of Page

jsmith8858
Dr. Cross Join

USA
7423 Posts

Posted - 12/29/2006 :  09:24:12  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
First off, you asked about overriding the + operator, not the division operator.

Secondly, are you asking about .NET or T-SQL?

Third, it is so extremely easy to handle divide by zero errors using either CASE or a simple custom function that I cannot think of any reason why you'd want to globally change the way an operator works, even if you could. Creating a simple UDF (User defined function) would result in code like this:

set @a= dbo.Div(@b,@c)

with a definition of Div as something like:

create function Div(@a int, @b int)
returns int
as
return case when @b=0 then 0 else @a/@b end

That would do the trick and make it very clear that you are using a custom function which can be easily looked at and verified to see what it does.

- Jeff

Edited by - jsmith8858 on 12/29/2006 11:00:02
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000