When I execute the SP, I get this error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘.’.
I tested the SQL without the case statement and it works, it returns everyone that is an admin.
ALTER PROCEDURE [dbo].[GetRoles]
AS
DECLARE @num varchar(25),
@reportid Decimal,
@dom varchar(10)
set @reportid = 1
set @dom = 'use5'
SELECT @num =
Case @reportid
WHEN 1 THEN
'select distinct u.id as userId, u.domain, u.isAdmin, u.email, u.canReport, a.[site],
a.bldgNum, a.dataCenterNum, l.shortName, l.[description], a.canApprove, a.canComplete
from locAdmin a inner join location l on (a.site=l.site and a.bldgNum = l.bldgNum
and a.dataCenterNum = l.dataCenterNum) right outer join [user] u on u.id=a.userId
and u.domain=a.domain where u.isAdmin = 1'
End
EXEC (@num)
Also distinct doesn’t filter out duplicate userid for some reason too. Some of the Userids are inputted 3x depending on what access they have (That’s the way it is setup before I came in)
You have limited
@numto 25 characters – but the string you’re setting it to is much longer than that – it’ll be truncated(also:
@numis a very odd and potentially misleading name for this – it suggest something numeric – and this is really more of a SQL statement or something – use the principle of least surprise when naming your variables!)Try something like this: