Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
c854104912
Starting Member
2 Posts |
Posted - 2009-06-23 : 00:29:11
|
Hey Guys,I have query where I'm making several joins across Microsoft's membership, role and profile provider tables. The goal is to return a list of users that includes a column denoting if the user has a record in the aspnet_profiles table but my case statement always evaluates to false. This example will work in SQL 2000 but not in 2005. I'm assuming something implicit is going on here and need a hand. Thanks,Chrisselect u.userid , UserName , LastActivityDate , Email , IsLockedOut , case p.userid when null then 0 else 1 end HasProfilefrom aspnet_Users uleft join aspnet_Membership m on u.userid = m.useridleft join aspnet_UsersInRoles uir on m.userid = uir.useridleft join aspnet_Roles r on uir.roleid = r.roleidleft join dbo.aspnet_Profile p on u.userid = p.userid |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-06-23 : 02:14:11
|
Change the case statement to the following and trycase NullIf(p.userid,Null)is null then 0 else 1 end HasProfile |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-23 : 02:20:44
|
try thisselect u.userid , UserName , LastActivityDate , Email , IsLockedOut , case when p.userid is null then 0 else 1 end HasProfilefrom aspnet_Users uleft join aspnet_Membership m on u.userid = m.useridleft join aspnet_UsersInRoles uir on m.userid = uir.useridleft join aspnet_Roles r on uir.roleid = r.roleidleft join dbo.aspnet_Profile p on u.userid = p.userid |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-06-23 : 02:55:57
|
| Problem is with CASE p.userid WHEN NULLYou can use this only when there is = comparison, for all the conditions (<, >, IN, NOT IN, IS NULL, NOT NULL) you need to change the CASE statment to as suggested by RakeshCASE WHEN p.userid IS NULLMangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
c854104912
Starting Member
2 Posts |
Posted - 2009-06-23 : 09:41:49
|
| raky's solution solved the problem. Thanks! |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-23 : 09:47:14
|
Welcome... |
 |
|
|
|
|
|
|
|