I'm trying to convert this query to a MySQL function
SET @v1 := (
SELECT count(id) as count
FROM article_category
where (title like "About Usd")
or (title like "About Usd-%" and title regexp '[0-9]$')
);
INSERT INTO `article_category`
(`title`,`meta_data`,`meta_description`)
VALUES
( IF(@v1 <= 0, "About Usd", CONCAT("About Usd","-",@v1) ),
"ddddD",
"ddddddd" );
This function should return the next available name so I can use it directly in an insert statement:
CREATE FUNCTION `get_next_unique_name`(tabel nvarchar(255),naem nvarchar(255)) RETURNS NVARCHAR(255)
DETERMINISTIC
BEGIN
SET @dd = SELECT count(id) as count FROM tabel where (title like naem) or (title like (naem+'-%') and title regexp '[0-9]$');
RETURN (naem+'-'[email protected]);
END