I would like to know how to concatenate two different values from two different columns from a SQL table using TSQL ? As you can see, I would like to concatenate those two different columns X e Y, resulting in the follow column table: Which query should be used here ? Answer You can use concat as
Tag: tsql
Is there a way to use IN and it evaluate values left to right in T-SQL?
Simplified example: I have been searching and cannot find a solid answer on this. I want to use the IN clause to get certain rows, but I want it to work left to right. In the example above, I would want a row for 2021, then 2015, then 2010 (assuming no seasons were null). Is there a way to make
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”
Remove minutes and seconds and then convert to UTC timezone
I have column with time stamp data like this 2021-12-09 08:01:00.520 I want to remove the minutes and second and then convert the date to UTC timezone in one line. I tried this code I get this result 2021-12-09 08:00:00.000 and I tried this code I get this result 2021-12-09 16:01:00.520 What I expected is 2021-12-09 16:00:00.000 How to combine
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