Getting this error with the following query in SQL Server 2012.
An expression of non-boolean type specified in a context where a condition is expected, near 'RETURN'.
CREATE FUNCTION [dbo].[GetPMResources](@UserResourceNo nvarchar(250))
RETURNS @Resources TABLE (
ResourceNo nvarchar(250) COLLATE Latin1_General_CS_AS not null,
Name nvarchar(250) COLLATE Latin1_General_CS_AS not null
)
AS
BEGIN
Declare @RoleID int, @UserDivision nvarchar(20)
SELECT TOP(1) @RoleID = r.ReportingRole, @UserDivision = r.DivisionCode
FROM Resource r
WHERE r.ResourceNo = @UserResourceNo
INSERT @Resources
SELECT r.ResourceNo,Name = r.ResourceNo + ' ' + r.Name
FROM Resource r WHERE r.ResourceNo IN
(
SELECT m.ResourceNo FROM JobMember m
JOIN Job j ON j.JobNo = m.JobNo
WHERE j.ProjectManagerNo = @UserResourceNo
OR
j.AlternateProjectManagerNo = @UserResourceNo
)
OR
(
SELECT m.ResourceNo FROM JobMember m
JOIN JobTask t ON t.JobTaskNo = m.JobTaskNo
WHERE t.TaskManagerNo = @UserResourceNo
OR
t.AlternateTaskManagerNo = @UserResourceNo
)
RETURN
END
While a Boolean two-valued logic with truth values “true” and “false” is best characterized by the famous “rule of the excluded middle” (or tertium non datur), non-Boolean logic violates this rule. The consequence is incompatible descriptions, which are central to the notion of complementarity.
SQL Boolean Expressions for the Unwary A Boolean expression is a way of expressing a condition or criterion which can be either true or false. Applying this to database tables we find that we often want to see "all of table x where column 1 is equal to this value, and column 3 is one of these four values".
A boolean is a data type that can store either a True or False value. There is no separate Boolean data type in SQL Server. Hence the bit data types are used instead. The value 1 is true & 0 as false.
Overview. The SQL Server NOT IN operator is used to replace a group of arguments using the <> (or !=)
An expression of non-boolean type specified in a context where a condition is expected
I also got this error when I forgot to add ON condition when specifying my join clause.
That is invalid syntax. You are mixing relational expressions with scalar operators (OR
). Specifically you cannot combine expr IN (select ...) OR (select ...)
. You probably want expr IN (select ...) OR expr IN (select ...)
. Using union would also work: expr IN (select... UNION select...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With