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.
Author |
Topic |
dehseth
Starting Member
18 Posts |
Posted - 2006-12-29 : 07:09:30
|
is there any way to override + operator for int type? |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-29 : 08:14:05
|
Do you think posting irrelevant question in mutiple forums will make it any good?[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76921[/url]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-12-29 : 08:35:40
|
dehseth -- Why the heck would you want to do that??? And what does that have to do with SQL Server ?- Jeff |
|
|
dehseth
Starting Member
18 Posts |
Posted - 2006-12-29 : 08:59:19
|
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 + 20if @c is 0 i want to see 20 in @a.why? cause i need to. if u know plz help |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-12-29 : 09:24:12
|
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 intas return case when @b=0 then 0 else @a/@b endThat 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 |
|
|
|
|
|