Created
July 24, 2020 07:16
-
-
Save ahmadshobirin/62a3d94d1fe5b24bc4795260ec15fcb8 to your computer and use it in GitHub Desktop.
GENERATE NO TRANSACTION INCREMENT OR SEQUENCE BY QUERY
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--GENERATE PLAN LINK200600807 FOR COLUMN 'ordersn' | |
--USED MAX NOT COUNT | |
--TESTED IN POSTGRESQL | |
-- FUNCTION ONLY POSTGRES | |
-- 1. '||' FOR CONCAT | |
-- 2. 'TO_CHAR' FOR GENERATE DATE FORMAT | |
-- 3. '::TEXTT' FOR CASTING | |
SELECT 'LINK' || to_char(CURRENT_DATE, 'YYMMDD') || | |
RIGHT( '0000' || | |
( | |
SELECT ((COALESCE(MAX(CAST(RIGHT(ordersn, 4) AS INT)),0))+1)::TEXT | |
FROM mar_tra_sales_order | |
where type_so = 'Link' | |
and status in ('APPROVED','CLOSED','USED','POST') | |
and ordersn != '' | |
and ordersn is not null | |
), 4) as newordersn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment