unpivot

Unpivot table with multiple columns and dynamic column names

丶灬走出姿态 提交于 2019-12-21 20:24:17
问题 I am trying to unpivot a table with multiple rows and columns. Each row needs to be extratced to 2 rows with specific columns and the column names need to be renamed and a new column needs to added based on the columns selected! I am including before and after sample data and a script to setup the data. CREATE TABLE #tmpProducts ( ProductId INT, ProductName nVARCHAR(100), B2B_GrossRevenue DECIMAL(10,2), B2B_DirectCost DECIMAL(10,2), B2B_NetRevenue DECIMAL(10,2), B2C_GrossRevenue DECIMAL(10,2)

Any .Net function or linq query to unpivot data

我的梦境 提交于 2019-12-21 18:32:39
问题 Is there any .net library available to unpivot excel data? I am currently using LinqToExcel framework to read data from spreadsheets, so not sure if there are dynamic linq queries available to perform the unpivot. Thanks for any suggestions. BTW, I am looking for a solution which could handle multiple columns. Example Original Table Product Location Customer1 Customer2 Customer3 A X 10 20 100 Destinaton Table Product Location Customer Demand A X Customer1 10 A X Customer2 20 A X Customer3 100

Any .Net function or linq query to unpivot data

本秂侑毒 提交于 2019-12-21 18:32:11
问题 Is there any .net library available to unpivot excel data? I am currently using LinqToExcel framework to read data from spreadsheets, so not sure if there are dynamic linq queries available to perform the unpivot. Thanks for any suggestions. BTW, I am looking for a solution which could handle multiple columns. Example Original Table Product Location Customer1 Customer2 Customer3 A X 10 20 100 Destinaton Table Product Location Customer Demand A X Customer1 10 A X Customer2 20 A X Customer3 100

Select values from multiple columns into single column

好久不见. 提交于 2019-12-21 07:24:20
问题 I have a table in a database that has 9 columns containing the same sort of data, these values are allowed to be null . I need to select each of the non-null values into a single column of values that don't care about the identity of the row from which they originated. So, for a table that looks like this: +---------+------+--------+------+ | Id | I1 | I2 | I3 | +---------+------+--------+------+ | 1 | x1 | x2 | x7 | | 2 | x3 | null | x8 | | 3 | null | null | null| | 4 | x4 | x5 | null| | 5 |

Transpose rows and columns without aggregate [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-21 05:56:13
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I have the following dataset Date Field1 Col1 Col2 Col3 2012/07/02 Customer1 CL DS RT 2012/07/03 Customer1 DS RT 700 2012/07/04 Customer1 DS RT 700 2012/07/02 Customer2 CL DS RT 2012/07/03 Customer2 DS RT 1500

GROUP BY or COUNT Like Field Values - UNPIVOT?

一世执手 提交于 2019-12-21 02:59:04
问题 I have a table with test fields, Example id | test1 | test2 | test3 | test4 | test5 +----------+----------+----------+----------+----------+----------+ 12345 | P | P | F | I | P So for each record I want to know how many Pass, Failed or Incomplete (P,F or I) Is there a way to GROUP BY value? Pseudo: SELECT ('P' IN (fields)) AS pass WHERE id = 12345 I have about 40 test fields that I need to somehow group together and I really don't want to write this super ugly, long query. Yes I know I

How to convert Column header to Row for loannumber [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-20 07:46:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am stuck in unpivoting. I have a table like #temp below. Using sql server 2008 r2 Select LoanNumber = 2000424385 ,[AmntType1] = 120.32 ,[AmntType2] = 131.52 ,[AmntType3] = 142.36 into #temp select * from #temp Above table has only one row and i want three rows as below LoanNumber Amount AmountType 2000424385

Dynamic Query in MySQL

痴心易碎 提交于 2019-12-20 06:34:02
问题 I have a following table. /------------------------------------\ | LocID | Year | Birth | Death | Abc | |------------------------------------| | 1 | 2011 | 100 | 60 | 10 | |------------------------------------| | 1 | 2012 | 98 | 70 | 20 | |..... | \------------------------------------/ I need the output to be (Condition LocID = 1) /---------------------\ | Event | 2011 | 2012 | |---------------------| | Birth | 100 | 98 | |---------------------| | Death | 60 | 70 | |---------------------| |

Split Multiple Columns into Multiple Rows

空扰寡人 提交于 2019-12-18 19:07:04
问题 I have a table with this structure. UserID | UserName | AnswerToQuestion1 | AnswerToQuestion2 | AnswerToQuestion3 1 | John | 1 | 0 | 1 2 | Mary | 1 | 1 | 0 I can't figure out what SQL query I would use to get a result set like this: UserID | UserName | QuestionName | Response 1 | John | AnswerToQuestion1 | 1 1 | John | AnswerToQuestion2 | 0 1 | John | AnswerToQuestion3 | 1 2 | Mary | AnswerToQuestion1 | 1 2 | Mary | AnswerToQuestion2 | 1 2 | Mary | AnswerToQuestion3 | 0 I'm trying to split

UNPIVOT on an indeterminate number of columns

十年热恋 提交于 2019-12-18 07:02:02
问题 How can I write a query that will unpivot a table that always has 1 row and many columns to a result set that has 2 columns: column_name and value. I understand the underlying structure of the table is where the real problem lies, but I cannot change that. This query must also not have any knowledge of the names and/or number of columns in the said table, as columns are being frequently added (again, I know, bad design, can't change it), and I don't want to have to update the query each time