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 2012 Forums
 Transact-SQL (2012)
 trying to make a function

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2014-10-17 : 09:53:00
What is the best way to code this?


CREATE FUNCTION [dbo].[CanSetRole]
(
@requestorRoleId int,
@roleId int
)
RETURNS bit
AS
BEGIN
RETURN

When @requestorRoleId =(16,62,47,52) and @RoleID in (1-38) then 1 else 0
When (@requestorRoleId = (16) and @RoleID in (40-64) then 1 else 0
When (@requestorRoleId = (62) and @RoleID in (56-64) then 1 else 0
When (@requestorRoleId = (47) and @RoleID in (40,48,49,50,55) then 1 else 0
ELSE 0

END
GO



Dave
Helixpoint Web Development
http://www.helixpoint.com

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-17 : 10:11:09
[code]
CREATE FUNCTION [dbo].[CanSetRole]
(
@requestorRoleId int,
@roleId int
)
RETURNS bit
AS
BEGIN
RETURN
case
When @requestorRoleId =(16,62,47,52) and @RoleID in (1-38) then 1
When (@requestorRoleId = (16) and @RoleID in (40-64) then 1
When (@requestorRoleId = (62) and @RoleID in (56-64) then 1
When (@requestorRoleId = (47) and @RoleID in (40,48,49,50,55) then 1
ELSE 0

END
[/code]
Go to Top of Page

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2014-10-17 : 10:18:30
Ya. Thats not right

Dave
Helixpoint Web Development
http://www.helixpoint.com
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-17 : 11:15:25
OK -- try this one:


CREATE FUNCTION [dbo].[CanSetRole]
(
@requestorRoleId int,
@roleId int
)
RETURNS bit
AS
BEGIN
RETURN
case
When @requestorRoleId in (16,62,47,52) and @RoleID in (1-38) then 1
When (@requestorRoleId in (16) and @RoleID between 40 and 64) then 1
When (@requestorRoleId in (62) and @RoleID between 56 and 64) then 1
When (@requestorRoleId in (47) and @RoleID in (40,48,49,50,55)) then 1
ELSE 0
END
END
Go to Top of Page
   

- Advertisement -