Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i not understand this procedure
SQL
ALTER PROCEDURE [dbo].aspnet_AnyDataInTables
    @TablesToCheck int
AS
BEGIN
   
    IF ((@TablesToCheck & 1) <> 0 AND



some code here
Posted
Updated 20-Feb-13 16:58pm
v6

The code is checking if a boolean add with the parameter provided i.e. @TablesToCheck is not equal to 0.
If the table count is an integer, then perhaps the and is not required.

& is a bitwise And[^].
 
Share this answer
 
Comments
Pradip Jadhav, India 20-Feb-13 23:24pm    
hi i not understand boolean add if i using value for @tablestoCHeck is 16
The code is doing a bitwise AND operation on the integer input.

So If @TablesToCheck is an even number it is returning 0 when you do
@TablesToCheck & 1 
and returning 1 if @TablesToCheck is odd.

so @TablesToCheck = 2,4,6 etc returns 0 and @TablesToCheck = 1,3,5 etc returning 1.

Not sure why this is done though.
 
Share this answer
 
Comments
Pradip Jadhav, India 20-Feb-13 23:35pm    
what is use of this in Procedure?
maxrockM 21-Feb-13 1:27am    
Please post the entire procedure
it means if @TablesToCheck is even number (1,3,5,7,9,11,...) then execute statements written in IF condition.

It is similar like modulo by 2
SQL
IF ((@TablesToCheck % 2) <> 0

Happy Coding!
:)
 
Share this answer
 
Comments
Pradip Jadhav, India 21-Feb-13 0:36am    
hi but if (@TablesToCheck & 16) <> 0 then
Aarti Meswania 21-Feb-13 0:54am    
you have used @TablesToCheck & 1 That is logic for checking even nos.

what you exactly want to do?
Aarti Meswania 21-Feb-13 0:58am    
if (@TablesToCheck & 16) <> 0 then

it will go inside if statement block when @TablesToCheck is 16,144,304... etc
The code is doing a bitwise AND operation on the integer input.

So If @TablesToCheck is an even number it is returning 0 when you do
Collapse | Copy Code
@TablesToCheck & 1
and returning 1 if @TablesToCheck is odd.

so @TablesToCheck = 2,4,6 etc returns 0 and @TablesToCheck = 1,3,5 etc returning 1.

Not sure why this is done though.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900