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
Tag: sql-server
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…
Month Name and Last date of each month for previous 3 months in sql
I’m analyzing customer transactions for the previous 3 months, excluding the current month, I would like to get the month names of the previous 3 months and the last date of each of the 3 months. —output —expected Answer You can use SQL Server EOMONTH() function to compute the last day of a …
Getting Count of Result Sets of SP (SP_MSForeachtable)
I was going to list all of the Tables in my DB which have no records. As same as most of the times I used SP_MSforeachtable like: And this gives me many result sets which I need to count them now. I know there are other ways to work with tables but I was thinking getting count of sys.sp_MSforeachtable (or
Filter Count Clause – One to Many relationship
I currently have two table where a versionLog can contain many ProductVersions. Following Sql Query: SELECT versionlog.[Name], ( SELECT COUNT(*) FROM dbo.ProductVersions productVersion …
How to concatenate two columns in my case using SQL? [closed]
I have 2 tables called Standards and StandardDetails Standards ItemID ItemCode BranchID ———————————— 135576 555 1111 135576 555 …
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 …
How to generate the sequence number based on condition in sql server
I need to display a New Sequence column value based on the Score 1 or 0. MonthlyDate Score New Sequence ———– —— ———- 2019-08-01 1 0 2019-08-02 0 1 2019-08-03 0 …