Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7077489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:25:47+00:00 2026-05-28T06:25:47+00:00

I’m trying to create DB2 trigger which is using the procedure VOTES_COUNT but when

  • 0

I’m trying to create DB2 trigger which is using the procedure VOTES_COUNT but when I try to create the trigger I get the error:

An unexpected token “” was found following “”. Expected tokens may
include: “SET status = 1”.. SQLCODE=-104, SQLSTATE=42601,
DRIVER=4.7.89

Here’s my code:

CREATE PROCEDURE VOTES_COUNT (IN username VARCHAR(15), OUT votesCount INT)
DYNAMIC RESULT SETS 1

P1: BEGIN

DECLARE C1 CURSOR FOR 
    SELECT COUNT(*) AS R1
        FROM VOTES
        WHERE USER = username;
OPEN C1;    
FETCH C1 INTO votesCount;   
CLOSE C1;

END P1 @

CREATE TRIGGER UPDATE_LEVEL
AFTER INSERT ON VOTES
REFERENCING NEW AS N
FOR EACH ROW
BEGIN ATOMIC
    DECLARE num INT;
    DECLARE status INT;
    CALL VOTES_COUNT(N.USERNAME, num);
    CASE
        WHEN num >= 300 
            THEN SET status = 5;
        WHEN num < 300 AND num >= 200
            THEN SET status = 4;
        WHEN num < 200 AND num >= 100
            THEN SET status = 3;
        WHEN num < 100 AND num >= 50
            THEN SET status = 2;
        ELSE
            SET status = 1;
    END CASE;
    UPDATE USERS SET STATUS = status WHERE USERNAME = N.USERNAME;
END @

Can you tell me what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:25:48+00:00Added an answer on May 28, 2026 at 6:25 am

    You can do this without stored procedure:

    CREATE TRIGGER UPDATE_LEVEL
    AFTER INSERT ON VOTES
    REFERENCING NEW AS N
    FOR EACH ROW MODE DB2SQL
    BEGIN ATOMIC
        DECLARE votesCount INT;
        DECLARE userStatus INT;     
        SET votesCount = (SELECT COUNT(*)
        FROM USERS
        WHERE USERNAME = N.USERNAME); 
    
        IF votesCount >= 300 THEN
            SET userStatus = 5;
        ELSEIF votesCount < 300 AND votesCount >= 200 THEN
            SET userStatus = 4;
        ELSEIF votesCount < 200 AND votesCount >= 100 THEN
            SET userStatus = 3;
        ELSEIF votesCount < 100 AND votesCount >= 50 THEN
            SET userStatus = 2;
        ELSE
            SET userStatus = 1;
        END IF;
    
        UPDATE USERS SET STATUS = userStatus WHERE USERNAME = N.USERNAME;
    END @
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.