SQL user defined function not run












2














I have situation where I want to generate invoice_id sequential for different product for multiple cities. I want to get generated invoice id according to different product and city.



My table temp look like



id  |order_id |product|city|invoice_id 
1 | 123 | 1 | 1 | FPU1
2 | 124 | 6 | 1 | PPU1


I want to get next invoice_id for product 1 and city 1 is FPU2.



For product 1 and city 2 is FBN1,product 6 and city 1 is PPU2 and so on ....



I create function but not run.Is anything wrong in function?



  CREATE function generate(p_id INT,  c_id INT) 
returns VARCHAR(50)

BEGIN
-- DECLARE v_new_id VARCHAR(50);
SELECT Concat(( CASE
WHEN t.product = 1 THEN "f"
WHEN t.product = 6 THEN "p" end ),
c.city_name, Cast(RIGHT(t.invoice, Length(t.invoice) - 3) AS UNSIGNED) + 1
) v_new_id
FROM temp AS t
JOIN city c
ON c.city_id = t.city
WHERE t.product = p_id
AND t.city = c_id;

RETURN( v_new_id );
end;


Get syntax error:



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 15 


###Line 15 is AND t.city = c_id;










share|improve this question


















  • 1




    i advice you to make a view instead where you generate the invoice_id
    – Raymond Nijland
    Nov 19 '18 at 13:31








  • 1




    Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
    – P.Salmon
    Nov 19 '18 at 13:42






  • 1




    also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
    – P.Salmon
    Nov 19 '18 at 13:52


















2














I have situation where I want to generate invoice_id sequential for different product for multiple cities. I want to get generated invoice id according to different product and city.



My table temp look like



id  |order_id |product|city|invoice_id 
1 | 123 | 1 | 1 | FPU1
2 | 124 | 6 | 1 | PPU1


I want to get next invoice_id for product 1 and city 1 is FPU2.



For product 1 and city 2 is FBN1,product 6 and city 1 is PPU2 and so on ....



I create function but not run.Is anything wrong in function?



  CREATE function generate(p_id INT,  c_id INT) 
returns VARCHAR(50)

BEGIN
-- DECLARE v_new_id VARCHAR(50);
SELECT Concat(( CASE
WHEN t.product = 1 THEN "f"
WHEN t.product = 6 THEN "p" end ),
c.city_name, Cast(RIGHT(t.invoice, Length(t.invoice) - 3) AS UNSIGNED) + 1
) v_new_id
FROM temp AS t
JOIN city c
ON c.city_id = t.city
WHERE t.product = p_id
AND t.city = c_id;

RETURN( v_new_id );
end;


Get syntax error:



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 15 


###Line 15 is AND t.city = c_id;










share|improve this question


















  • 1




    i advice you to make a view instead where you generate the invoice_id
    – Raymond Nijland
    Nov 19 '18 at 13:31








  • 1




    Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
    – P.Salmon
    Nov 19 '18 at 13:42






  • 1




    also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
    – P.Salmon
    Nov 19 '18 at 13:52
















2












2








2







I have situation where I want to generate invoice_id sequential for different product for multiple cities. I want to get generated invoice id according to different product and city.



My table temp look like



id  |order_id |product|city|invoice_id 
1 | 123 | 1 | 1 | FPU1
2 | 124 | 6 | 1 | PPU1


I want to get next invoice_id for product 1 and city 1 is FPU2.



For product 1 and city 2 is FBN1,product 6 and city 1 is PPU2 and so on ....



I create function but not run.Is anything wrong in function?



  CREATE function generate(p_id INT,  c_id INT) 
returns VARCHAR(50)

BEGIN
-- DECLARE v_new_id VARCHAR(50);
SELECT Concat(( CASE
WHEN t.product = 1 THEN "f"
WHEN t.product = 6 THEN "p" end ),
c.city_name, Cast(RIGHT(t.invoice, Length(t.invoice) - 3) AS UNSIGNED) + 1
) v_new_id
FROM temp AS t
JOIN city c
ON c.city_id = t.city
WHERE t.product = p_id
AND t.city = c_id;

RETURN( v_new_id );
end;


Get syntax error:



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 15 


###Line 15 is AND t.city = c_id;










share|improve this question













I have situation where I want to generate invoice_id sequential for different product for multiple cities. I want to get generated invoice id according to different product and city.



My table temp look like



id  |order_id |product|city|invoice_id 
1 | 123 | 1 | 1 | FPU1
2 | 124 | 6 | 1 | PPU1


I want to get next invoice_id for product 1 and city 1 is FPU2.



For product 1 and city 2 is FBN1,product 6 and city 1 is PPU2 and so on ....



I create function but not run.Is anything wrong in function?



  CREATE function generate(p_id INT,  c_id INT) 
returns VARCHAR(50)

BEGIN
-- DECLARE v_new_id VARCHAR(50);
SELECT Concat(( CASE
WHEN t.product = 1 THEN "f"
WHEN t.product = 6 THEN "p" end ),
c.city_name, Cast(RIGHT(t.invoice, Length(t.invoice) - 3) AS UNSIGNED) + 1
) v_new_id
FROM temp AS t
JOIN city c
ON c.city_id = t.city
WHERE t.product = p_id
AND t.city = c_id;

RETURN( v_new_id );
end;


Get syntax error:



#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 15 


###Line 15 is AND t.city = c_id;







mysql sql phpmyadmin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 13:22









Satish

223413




223413








  • 1




    i advice you to make a view instead where you generate the invoice_id
    – Raymond Nijland
    Nov 19 '18 at 13:31








  • 1




    Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
    – P.Salmon
    Nov 19 '18 at 13:42






  • 1




    also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
    – P.Salmon
    Nov 19 '18 at 13:52
















  • 1




    i advice you to make a view instead where you generate the invoice_id
    – Raymond Nijland
    Nov 19 '18 at 13:31








  • 1




    Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
    – P.Salmon
    Nov 19 '18 at 13:42






  • 1




    also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
    – P.Salmon
    Nov 19 '18 at 13:52










1




1




i advice you to make a view instead where you generate the invoice_id
– Raymond Nijland
Nov 19 '18 at 13:31






i advice you to make a view instead where you generate the invoice_id
– Raymond Nijland
Nov 19 '18 at 13:31






1




1




Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
– P.Salmon
Nov 19 '18 at 13:42




Perhaps you didn't set delimiters - dev.mysql.com/doc/refman/8.0/en/stored-programs-defining.html
– P.Salmon
Nov 19 '18 at 13:42




1




1




also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
– P.Salmon
Nov 19 '18 at 13:52






also you cannot return a result set from a trigger, perhaps ) v_new_id should be ) into v_new_id and the declared variable uncommented.
– P.Salmon
Nov 19 '18 at 13:52














1 Answer
1






active

oldest

votes


















0














Need to set delimiters .



Thanks @P.Salmon for valuable comment and link



For set delimiter manually follow



For phpmyadmin user follow this link






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375585%2fsql-user-defined-function-not-run%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Need to set delimiters .



    Thanks @P.Salmon for valuable comment and link



    For set delimiter manually follow



    For phpmyadmin user follow this link






    share|improve this answer


























      0














      Need to set delimiters .



      Thanks @P.Salmon for valuable comment and link



      For set delimiter manually follow



      For phpmyadmin user follow this link






      share|improve this answer
























        0












        0








        0






        Need to set delimiters .



        Thanks @P.Salmon for valuable comment and link



        For set delimiter manually follow



        For phpmyadmin user follow this link






        share|improve this answer












        Need to set delimiters .



        Thanks @P.Salmon for valuable comment and link



        For set delimiter manually follow



        For phpmyadmin user follow this link







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 14:40









        Satish

        223413




        223413






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375585%2fsql-user-defined-function-not-run%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]