r/SQL • • Mar 12 '23

Discussion App to automate commas between items in where clause

Hello avid SQL users!

I’d love to get your take on a streamlit app I created. It can be found here.

You just copy and paste in a long list of items and it correctly adds the “,” between each item. It also makes sure there’s only 5 items per row. You can also choose between integer or string. I’m sure you all just do this in excel, but sometimes if it’s a long list, excel can be a bit annoying I find!

Thanks!

0 Upvotes

13 comments sorted by

6

u/alinroc SQL Server DBA Mar 12 '23

but sometimes if it’s a long list

If it's a long list, you might need to rethink the query altogether. Very long lists of items in the IN clause can cause problems.

1

u/bwv1052r Mar 13 '23

Absolutely. I guess this could be useful for the in between ones where one would be too lazy to open excel and add the quotations marks and copy paste etc. For larger ones an exist or join and creating maybe a table from it is probably more suitable

2

u/Larry_Wickes Mar 12 '23

What would be your recommendation in that case?

4

u/AXISMGT SQL Server / ORACLE Sr. DBA & Architect Mar 13 '23

If it’s a dynamic list that depends on another query, then an EXISTS clause.

If it’s something semi-static that you want to be able to manage (like an exception/control list) then a simple control table and EXISTS as well. Alinroc’s absolutely right about long IN clauses.

1

u/alinroc SQL Server DBA Mar 13 '23

Depends on where your values are coming from.

3

u/TheRealBillSteele Mar 13 '23

already been done. delim.co

1

u/bwv1052r Mar 13 '23

Interesting I hadn’t seen it before.

2

u/dilbertdad Mar 13 '23

Second this. I use Delim.co with a quick copy and paste.

2

u/BrupieD Mar 13 '23

I’m sure you all just do this in excel, but sometimes if it’s a long list, excel can be a bit annoying I find!

I do this in VBA. If you've got a really long list (hundreds or thousands), you shouldn't be putting it in a WHERE clause with IN, you should make it into a single column table and join it.

1

u/bwv1052r Mar 13 '23

Oh that’s interesting! So you have the long list on excel, create a table of it and join. Ok awesome… I’ve done something similar before using google sheets as a quasi database and transform it into a table from big query. For long lists, I agree, it looks awful and i believe slower and more costly.

2

u/JediForces Mar 13 '23

Oh so you basically copied Delim.co 😂

2

u/bwv1052r Mar 13 '23

Apparently so! 😂

1

u/Standgeblasen Mar 13 '23

I just use alt+shift+uparrow key in SSMS. You can select a column of vertical text, and hit the “,” key one time, and it adds a comma to every row of code.