User defined Function to check if Rent has more then 3 games

I how you can help me with the following problem. We want to use Powerbi to get reports but first we want to implement a constraint on our database. Because this constraint needs to check another table we want to use a User defined Function.

The function has to check if more then 3 games are being rented. To see if a product(Artikel) is a Game or Console we use the column SPEL_OF_CONSOLE.

How can I see this in a function.

enter image description here

I Wrote this function:

I wrote this function

    (@HUUROVEREENKOMSTNR INT)
    RETURNS BIT --1 or 0
    AS
       BEGIN
       DECLARE @Returnvalue bit =1;
       IF COUNT(*) = 3(
          SELECT v.[Barcode] FROM VERHUURDE_ARTIKELEN v INNER JOIN ARTIKEL A on v.[BARCODE] = A.[BARCODE]
          WHERE @HUUROVEREENKOMSTNR = v.[HUUROVEREENKOMSTNR]
          AND [SPEL_OF_CONSOLE] = 'SPEL'
       )
       SET @Returnvalue = 1;
       ELSE SET @Returnvalue = 0;
       END;
    GO 

However I get the following Error:

Incorrect syntax near the keyword 'ELSE'.



from Recent Questions - Stack Overflow https://ift.tt/3E7TZZh
https://ift.tt/3mhAE1x

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)