sql stored proc
-
The following is the way i want to implement this. that is..to check iff permissiosn()&2=0x2....permissions()&32=0x20 and so on... CREATE PROCEDURE balli @ioparm int output, @oparm int output AS BEGIN SET NOCOUNT ON IF PERMISSIONS() &@ioparm=0x@oparm SELECT 1 ELSE SELECT 0 END The above sql proc gives syntax error..how do i change it?? ranjani
-
The following is the way i want to implement this. that is..to check iff permissiosn()&2=0x2....permissions()&32=0x20 and so on... CREATE PROCEDURE balli @ioparm int output, @oparm int output AS BEGIN SET NOCOUNT ON IF PERMISSIONS() &@ioparm=0x@oparm SELECT 1 ELSE SELECT 0 END The above sql proc gives syntax error..how do i change it?? ranjani
A couple of problems: your parameters should not be specified as
output
, because you're passing the values into the stored procedure. The parameters are also badly named - indeed, I'm not sure you need two parameters, because you're just trying to see if a particular flag is set. The syntax error is coming from0x@oparm
. The prefix0x
tells SQL Server that the following characters should be interpreted as a hexadecimal number literal. If you want to do that, specify hex when assigning a value to the parameter, don't include it in the query text.@
isn't a valid character in a hex literal, so SQL Server complains. With that in mind, I would justSELECT PERMISSIONS()
and perform the mask operation in client-side code. Testing each bit separately is a waste of network and server resources. In Visual C++, you use the&
operator to mask, then==
to compare.==
has a higher precedence than&
, so you need to use brackets to ensure that the AND operation is done first. In VB, useAnd
to mask and=
to compare.