开发者

sql not evaluating equal string comparison correctly

i have a proc that loads a users table and in doing so makes an association between users and their managers. i have the simple select below to figure out maangerId for each user record. i see there is a manager that should be assign开发者_运维技巧ed to a user but the user gets a blank and the assignment of managerId is missing.

DECLARE @managerId INT     
SET @managerId = NULL    

IF @CorpManagerDN IS NOT NULL    
BEGIN    

 IF EXISTS (SELECT 69 FROM Employees WITH(NOLOCK) WHERE CorpManagerDN = @CorpManagerDN)    
 BEGIN    
  SELECT @managerId = EmployeeId FROM Employees WHERE CorpDN = @CorpManagerDN   
 END    
END 

the userId is a self incrmenting field so that works out well, and the managerId field is populated with the logic above. i notice sometimes i get blank managerId values when i see CorpManagerDN values like

CN=Tsahalis\, Peter NBKPVUD,OU=Pre-BAND,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com

and i see CORPDN value of the manager like

CN=Tsahalis\, Peter NBKPVUD,OU=Pre-BAND,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com

but the sql evaluation doesn't match them?


They seem equal to me

select 
case when   
    'CN=Tsahalis\, Peter NBKPVUD,OU=Pre-BAND,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com' 
      = 'CN=Tsahalis\, Peter NBKPVUD,OU=Pre-BAND,OU=Accounts,OU=BAND,DC=corp,DC=bankofamerica,DC=com'
     THEN 1
     else 0
END
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜