Can I create column values from say '80000001' to '80001000' using Python?

Hi, I'm trying to create a numerical string (nvarchar(8)) for employee ID's and I want to create test data out of range of real data.  The simplest would be to start with '80000001' and increment for each row until 1000 rows which would be '80001000'.  How can I do this?
Tagged:

Best Answer

  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Hi @Mij!

    I believe you should be able to achieve this with a python script... 

    Using something like the "numbered labels" example in https://documentation.red-gate.com/sdg3/using-generators/example-python-scripts his seems to give the desired effect:

    def main(config):
        return list(Sequence(config["n_rows"])) # The max number of rows available
    def Sequence(max):
        for i in range(1, max + 1): # Modify the range start and end points in order to offset the row number
            yield "8000{0:0>3}".format(i) # Format the output string here





    Hope that helps!

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Answers

  • MijMij Posts: 23 Bronze 1
    Once I got the script syntax and indenting right and changed to 0>4, it worked the way we needed.  Thank you.  I just need to understand Python a little more.
Sign In or Register to comment.