Skip to content

Tag: sql-server

Executing multiple drop table statements in 1 sql file

I am trying to drop 200 tables from my database and save the sql statements to 1 .sql file so they can be run in one go on each copy of the database. I would like to use a separate drop table statement for each table so I can easily reference what line any errors appear on. I have tried

Adding Random Id for each unique value in table

I have the table like I want the result to be like : The same ID should have same random_ids. I’m using the update statement to generate the Random_IDs after creating the table. Is there something else that I need to add to the update statement? Please advise. Answer Why would you use update for this? J…

T-SQL Query Column based on filtered condition

I could do this rather easily in Python (or any other language), but I’m trying to see if this is possible with pure T-sql I have two tables: Table A has a bunch of general data and timestamps with each row Table B is considered metadata So the general data is referenced to a “RunNo”. The ti…

Find the count of words in string

SQL: How to find the count of words in following example? Subquestions: How to count spaces? How to count double/triple/… spaces as one? answer by Gordon Linoff here How to avoid counting of special characters? Example: ‘Please , don’t count this comma’ Is it possible without string_sp…

Adding a computed column that uses MAX

I need to create a sequential number column for record number proposes I am OK with losing sequence if I delete a row from the middle of the table For example 1 2 3 If I delete 2, I am ok with new …