I have a SQL view for my User & person table called vw_user. This view simply joins the user and person table. The view is below. When I select from the view and filter by username, I do not get a result however when I copy SQL from the view into a separate query, and filter by username, I get a result. This applies to both, stored procedures and manually running the queries in SSMS. Could this be a bad index or some sort of SQL caching the needs to be cleared?
ALTER VIEW [civic].[vw_User]
AS
SELECT TOP (1000)
p.[Email]
,p.[FirstName]
,p.[MiddleName]
,p.[LastName]
,p.[Phone]
,u.*
,u.[PersonID] as ID -- temp for for previous version
,p.[Address1] as [Address] -- temp for for previous version
FROM [civic].[User] u
JOIN [civic].[Person] p on p.PersonID=u.PersonID
GO
When I run the select below, I do not get a result:
SELECT
u.*
FROM [civic].[vw_User] u
WHERE
-- t4-where begin
u.[Username] = 'exampleUser'
-- t4-where end
When I run the query below, I do get a result:
SELECT TOP (1000)
p.[Email]
,p.[FirstName]
,p.[MiddleName]
,p.[LastName]
,p.[Phone]
,u.*
,u.[PersonID] as ID -- temp for for previous version
,p.[Address1] as [Address] -- temp for for previous version
FROM [civic].[User] u
JOIN [civic].[Person] p on p.PersonID=u.PersonID
WHERE u.[Username] = 'exampleUser'
UPDATE: We have over 1000 users and removing the top 1000 from the view corrected the problem.