Hello everyone I have two tables named as au.aspnetusers and au.aspnetuserclaims .I have taken the data from both these tables and joined tables and joined on the base.
select * from au.AspNetUsers Join Au.AspNetUserClaims ON Au.AspNetUserClaims.UserId=Auth.AspNetUsers.Id
Where (Au.AspNetUserClaims.ClaimType='TrialEndOn' AND CONVERT(varchar(10), Au.AspNetUserClaims.ClaimValue,111) > CONVERT(varchar(100),GETDATE(),120))
AND (Au.AspNetUserClaims.ClaimType='TrialStatus' AND Au.AspNetUserClaims.ClaimValue='inactive')
I have used this query it's return data .
But this query not retrun any result it's just return 0
select * from au.AspNetUsers Join Au.AspNetUserClaims ON
Au.AspNetUserClaims.UserId=Auth.AspNetUsers.Id
Where (Au.AspNetUserClaims.ClaimType='TrialEndOn' AND CONVERT(varchar(10), Au.AspNetUserClaims.ClaimValue,111) > CONVERT(varchar(100),GETDATE(),120))
AND (Au.AspNetUserClaims.ClaimType='TrialStatus' AND Au.AspNetUserClaims.ClaimValue='inactive')
Sourabh DhimanPosted May 10, 2023, 10:59 AM
Any other help me
Sourabh DhimanPosted May 10, 2023, 10:56 AM
Same replay and not working
Prathap ReddyPosted May 10, 2023, 10:40 AM
It seems that the issue with the query is in the
WHEREclause. Specifically, the conditions forClaimTypeandClaimValueare both being applied to the same row in theAspNetUserClaimstable, which cannot be true since the same row cannot have two different values for theClaimTypecolumn. Therefore, the query is returning no results.To fix this, you should change the
WHEREclause to use theORoperator instead ofAND, so that it will match rows that have either of the two conditions. Here's the corrected query:sql:
SELECT *
FROM auth.AspNetUsers
JOIN Auth.AspNetUserClaims ON auth.AspNetUserClaims.UserId = auth.AspNetUsers.Id
WHERE
(auth.AspNetUserClaims.ClaimType = 'TrialEndOn' AND CONVERT(varchar(10), auth.AspNetUserClaims.ClaimValue,111) > CONVERT(varchar(100),GETDATE(),120))
OR
(auth.AspNetUserClaims.ClaimType = 'TrialStatus' AND auth.AspNetUserClaims.ClaimValue = 'inactive')
the query should correctly join the two tables and return the expected results.
Sourabh DhimanPosted May 10, 2023, 10:37 AM
I have changed not working
select * from auth.AspNetUsers
Join Auth.AspNetUserClaims ON auth.AspNetUserClaims.UserId=auth.AspNetUsers.Id
Where (auth.AspNetUserClaims.ClaimType='TrialEndOn' AND CONVERT(varchar(10), auth.AspNetUserClaims.ClaimValue,111) > CONVERT(varchar(100),GETDATE(),120))
AND (auth.AspNetUserClaims.ClaimType='TrialStatus' AND auth.AspNetUserClaims.ClaimValue='inactive')
Prathap ReddyPosted May 10, 2023, 10:32 AM
It looks like the second query you provided is the same as the first one, with one small difference in the syntax: the table alias used for the
AspNetUserstable is different (Authinstead ofAu). This could be the reason why the second query is not returning any results, because it's not correctly joining the two tables.To fix this, you should make sure to use the same table alias (
Au) for both tables in the query. Here's the corrected query:sql code:
select * from au.AspNetUsers
Join Au.AspNetUserClaims ON Au.AspNetUserClaims.UserId=au.AspNetUsers.Id
Where (Au.AspNetUserClaims.ClaimType='TrialEndOn' AND CONVERT(varchar(10), Au.AspNetUserClaims.ClaimValue,111) > CONVERT(varchar(100),GETDATE(),120))
AND (Au.AspNetUserClaims.ClaimType='TrialStatus' AND Au.AspNetUserClaims.ClaimValue='inactive')
With this change, the query should correctly join the two tables and return the expected results.