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 2005 Forums
 Transact-SQL (2005)
 Function that returns the oposite value

Author  Topic 

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-07-07 : 19:03:35
Hi guys. Is there any function that returns the oposite value? like :

declare @myValue bit

set @myValue = 1

Select function(@myValue)

it should return 0 or false.

Thank you.

chrispy
Posting Yak Master

107 Posts

Posted - 2007-07-07 : 19:38:24
If you are thinking 'invert' I am pretty sure there is nothing like it in T-SQL.

I use this :

CREATE function dbo.invert
(
@i int
)
returns int
as

begin

IF @i = 0 SET @i = 1
ELSE SET @i = 0

return @i

end
Go to Top of Page

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-07-07 : 20:24:20
hmmmm.... thank you chrispy
Go to Top of Page

nice123ej
Starting Member

48 Posts

Posted - 2007-07-08 : 02:28:33
you can use this to select the invert value

select 1 - @myvalye
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-08 : 04:32:58
CREATE function dbo.invert
(
@i bit
)
returns bit
as

begin
return @i ^ 1
end


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -