Hi,
I have a table that consists of a column with codes in it.
Security
---------
user as varchar(10)
areaassigned as varchar(10)
Codes varchar(80)
codesused as varchar(80)
USER1 AREA1 1515151;4444444;5454144;5545454;4454544;4544141
USER2 AREA2 222222;333333;3232322;1212121;2222223;4343434;1131213
When a user signs in.. I check the code the enter using charindex..
now since charindex will return 0 in the code below.. my logic does not make any sense.. What i need here is a null to indicate that the Code entered by the user does not belong the the area they are assigned to.
If @userid = 'USER1' and @AccessCode = '222222' and @Area = 'AREA1'
The CHARINDEX returns a 0 indicating this code was not used...
But it returns 0 also when the code is not found..
Thanks for your help...
DECLARE @count as int
SET @count = (SELECT CHARINDEX(@AccessCode,codesused)
FROM Security
WHERE userid = @userid
AND Area = @Area)
IF @count <>0
BEGIN
SET @ReturnValue = 'CODE USED'
END
ELSE
BEGIN
PRINT 'DO SOMETHING'
END