Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - An expression of non-boolean type specified in a context where a condition is expected, near 'RETURN'

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
like image 682
Sohail xIN3N Avatar asked May 29 '14 08:05

Sohail xIN3N


People also ask

What is a non Boolean?

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.

What is a Boolean expression in SQL?

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".

What is a boolean in SQL Server?

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.

How do you write not in SQL?

Overview. The SQL Server NOT IN operator is used to replace a group of arguments using the <> (or !=)


2 Answers

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.

like image 191
Lori Kent Avatar answered Oct 02 '22 19:10

Lori Kent


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...)

like image 45
Remus Rusanu Avatar answered Oct 02 '22 19:10

Remus Rusanu