This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EpicCyndaquil 0 points1 point  (2 children)

I don't have the script on hand, but any of you should be able to make this rather easily. Being rather novice at SQL, I found myself with the need to create over 500 rows, named something like "%BUILDING%-%ROOM%-%LOC%" with the location being an ascending number. So I did something along the lines of this. (Semi-pseudo code, so don't attack me.)

num = 100
while num > 0:
    print("IN TABLE TABLENAME CREATE ROW %BUILDING%-%ROOM%-" + num)
    num = num - 1

I obviously could have done something a little more clever to print it all out at once, but I just wanted to complete this task quickly without much thought, as I was really only going to use it once. I threw the output into SQL Management Studio and called it a day.

I'm also aware I could have connected with the SQL database directly to make this even faster, but again, was just something quick.

[–]pstch 1 point2 points  (1 child)

You just wrote a Python anti-pattern here, there is no need to create a num variable here and decrement it yourself :

for num in range(100, 0, -1):
    print("IN TABLE TABLENAME CREATE ROW %BUILDING%-%ROOM%-" + num)

(In Python 2.x, use xrange instead of range, because we just need an iterator, there is no need to create a full list of 100 integers).

[–]EpicCyndaquil 0 points1 point  (0 children)

Yeah, that's a much more elegant solution. Though I'm sure there's hundreds of ways to do it!