Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CHARINDEX won't do here...
Message
From
14/12/2004 18:29:50
Alvin Lourdes
Children and Youth Services Cluster
Toronto, Ontario, Canada
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
CHARINDEX won't do here...
Miscellaneous
Thread ID:
00969303
Message ID:
00969303
Views:
51
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
Next
Reply
Map
View

Click here to load this message in the networking platform