I am trying to create a report, but my query seems to be causing problems even though it runs fine on Rapid SQL 8.5. The specific error message is below:
Could not update a list of fields for the query. Verify that you can connect to the data source and that your query syntax is correct. Invalid column name 'MMTEST%'.
To continue without updating the fields list, click OK
My query is here below:
select count(*), No.mm_territorynumber as NO,usr.domainname, usr.systemuserid, usr.fullname, usr.mm_PrimaryTeamIdName as PrimaryTeamName
from systemuser usr WITH (nolock)
inner join dbo.teammembership mem with (nolock) on mem.systemuserid = usr.systemuserid
inner join dbo.team team with (nolock) on team.teamid = mem.teamid and mm_teamcategorycode is not null
inner join BusinessUnit bu WITH (nolock) on usr.BusinessUnitId = bu.BusinessUnitId
inner join BusinessUnit NO WITH (nolock) on NO.BusinessUnitId = bu.mm_GUID
where usr.systemuserid in (
select usr.systemuserid from systemuser usr WITH (nolock)
inner join dbo.teammembership mem with (nolock) on mem.systemuserid = usr.systemuserid
inner join dbo.team team with (nolock) on team.teamid = mem.teamid
and mm_teamcategorycode = '930750004'
where usr.isdisabled = 0
intersect
select usr.systemuserid from systemuser usr WITH (nolock)
inner join dbo.teammembership mem with (nolock) on mem.systemuserid = usr.systemuserid
inner join dbo.team team with (nolock) on team.teamid = mem.teamid
and mm_teamcategorycode = '930750000'
where usr.isdisabled = 0
) and
"MMTEST%" not in (select usr.domainname from systemuser usr) and
--usr.domainname not like "MMTEST%" and
usr.systemuserid = team.AdministratorId -- Only team adminstrators
group by No.mm_territorynumber, usr.domainname, usr.systemuserid, usr.fullname, usr.mm_PrimaryTeamIdName
having count(*) = 2
order by NO.mm_territorynumber, usr.fullname;
I have already done some research to ensure that my specific question had already not been answered. Here are some of the links that I've visited:
could not create a list of fields for the query
Is there somewhere that I accidentally selected a column multiple times? After reviewing my code it doesn't seem so, but I am also very new to SQL so there may be some control flow issues that I don't understand. Any help would be appreciated.
EDIT: It seems that MMTEST% has been created as a column, but I have no idea why that happens.
Use single quotes instead of double quotes to filter out specific words in a value.