Skip to content
Advertisement

Tag: sql-server-2008

Transform and group row data into columns

I’m looking for a way to combine different rows into a single row with columns. Let’s take this example table: Desired output: Please note that Data centers are not necessarily these three, they can be N different data centers that I will not know in advance. Answer With a known set of sourceDataCenter values, you can just use a simple

Sql Server 2008 Update query is taking so much time

I have a table name Companies with 372370 records. And there is only one row which has CustomerNo = ‘YP20324’. I an running following query and its taking so much time I waited 5 minutes and it was still running. I couldn’t figure out where is the problem. Answer You don’t have triggers on update on that table? Do you

Drop Several Tables at Once

I have some tables that I need to drop on a regular basis. The names of the tables sometimes change but the table names always begin with ‘db_comp_temp’. Is it possible to write some SQL that will in effect do something like: Thanks in advance, Answer No, there is no wildcard support in DDL. Or: You could also do it

sql-ex exercise 39 failed on second server error?

Exercise 39: Define the ships that “survived for future battles”; being damaged in one battle, they took part in another. Database Schema: http://www.sql-ex.ru/help/select13.php#db_3 My approach: sql-ex says Your query produced correct result set on main database, but it failed test on second, checking database correct result matched with my output. Where I failed? Answer Solved! needed to add Distinct

Unpivot with column name

I have a table StudentMarks with columns Name, Maths, Science, English. Data is like I want to get it arranged like the following: With unpivot I am able to get Name, Marks properly, but not able to get the column name in the source table to the Subject column in the desired result set. How can I achieve this? I

Advertisement