Skip to content
Advertisement

Tag: tsql

T-SQL :: TRUNCATE or DELETE all tables in schema

I need to TRUNCATE or DELETE all tables in schema. I found this code: but on AdventureWorks it gives me: So I found this alternative code: But the result is the same: How to TRUNCATE or DELETE all tables in schema? Answer You simply need to wrap your “delete from all the tables” script with a “drop all foreign keys”

SQL Counting Rows based on break values

Frequently I need to do something in SQL Server that I just don’t know how to do properly. Basically, if I have a table #sample that is like this: DEPARTMENT DATE ACCOUNTING A FINANCE A PAYROLL A ACCOUNTING B PAYROLL A FINANCE A PAYROLL B PAYROLL C I need to query that table to get an output that is this:

Is there a more efficient way to append multiple columns from the same table?

I’d like to return multiple values from the same record, with different columns of the same type appended under one another. I could do multiple joins, but that seems very inefficient because of the multiple table scans. Returns: VisID Vis Home HomeID arenn001 Nolan Arenado Colin Moran morac001 badeh001 Harrison Bader Anthony Alford alfoa002 carld002 Dylan Carlson Yoshi Tsutsugo tsuty001

Find duplicate data in last 1 hour

I am looking for a SQL script to find the data which has more than 2 entries in last 1 hour. I have a table having user_id & event_time. I want a way to find out if the user_id has more than 1 entries in last 1 hour. I have tried below till now: Create temp table to put all

How can I get a query displayed monthly with a subquery

I have a query here with a subquery. This shows me the complete result for the year. How do I get it to be displayed to me on a monthly basis. I’ve tried a few things but always get an error message Here my query The result should look like this: Thank you Answer You can probably simplify this by

Finding who called who

I have these two tables. Subscriber table contains SubscriberID and his Phone number. NetworkP2P contents SubscriberID, to who he has called AddresseeNumber and when the call started, ended. Example data: Subscriber NetworkP2P Not all Phone numbers match the ones that Subscribers have. How would I approach this, if I wish to have which outputs subscribers who have been in contact

Need to update column from derived column of select statement

I’ve this below select statement. Over there I’ve 2 derived columns EmpContbtnWithoutTax and EmpContbtnWithTax I wanted to have that data permanently in that same table EmpPFContributionTest Need help to have that update query for EmpPFContributionTest table which update the respective rows of EmpContbtnWithoutTax and EmpContbtnWithTax columns permanently. Update script which I was trying for 1 column first mentioned below Answer

Advertisement