Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

snowflake sql i need to generate column with 0000001 and end with as increment by 0000001

i have tried with sequence in snowflake but i need my first values need to start with 0000001 and end with increment as of
RecordID
0000001
0000002
0000003
0000004
0000005
0000006
0000007
0000008
0000009
0000010
0049443 –like this …but i am not able to achieve by sequence in snowflake?

drop TABLE foo
CREATE OR REPLACE TABLE foo (n NUMBER)
INSERT INTO foo VALUES (100), (101), (102)
SELECT n, s.nextval FROM foo, TABLE(GETNEXTVAL(seq1)) s

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

What about using GENERATOR and then using LPAD to account for the leading zeros?

SELECT 
  LPAD(rn, 6, '0') as padded_num 
FROM 
  (
    SELECT 
      seq4() as s, 
      row_number() over (
        order by 
          seq4()
      ) as rn 
    FROM 
      TABLE(
        GENERATOR(rowcount => 100)
      )
  ) rs
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading