Merge data into one column - sql server 2012

Bulbul

How can I merge data into one column for different account numbers. Currently, it looks like this.

TableA.Order  TableA.Question  TableB.Response
1             a                Null
1             b                James
1             c                Null
2             d                Zebra
2             T                Null

However, I want it to merge like below:

 TableA.Order  NewColumn
   1             a
   1             b
   1             c
   1             James
   2             d
   2             T
   2             Zebra
Rigel1121

Base from my understanding of your question. I devised a solution which answers to it. See my query below:

SELECT * FROM TableA
UNION ALL
SELECT B.Order1,A.Response From 
   (
    (SELECT ROW_NUMBER()OVER(ORDER BY Response)PK,* FROM TableB) A Left Join 
    (SELECT ROW_NUMBER()OVER(ORDER BY Order1)PK,* FROM TableA) B On A.PK=B.PK 
   )
Where Response IS NOT NULL

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

SQL Server- Merge rows into one column and take maximum count

分類Dev

How to search a column name in all tables in a database in SQL Server 2012?

分類Dev

How to get COUNT(*) from one partition of a table in SQL Server 2012?

分類Dev

merge 2 data frames in a loop for each column in one of them

分類Dev

Merge ranges in one column

分類Dev

Merge multiple rows into one row using SQL Server?

分類Dev

SQL Server - Merge multiple query results into one result set

分類Dev

Show One Column Data as Two Columns in SQL

分類Dev

SQL Server MERGE Slow

分類Dev

SQL Server MERGE Slow

分類Dev

Numbering islands in SQL Server 2012

分類Dev

SQL Server 2012 Pivot Table

分類Dev

Restore SQL Server 2012 error

分類Dev

How to combine multiple rows into one row and multiple column in SQL Server?

分類Dev

Retrieve sorted data based on one numeric column in SQL

分類Dev

T SQL Group column with accumulating data in one record

分類Dev

SQL sum data between 2 dates in one column

分類Dev

SQL Server 2012: How to get up to 5 hierarchy levels of data from original to derived product table

分類Dev

SQL Server: Dynamically create Column Names from JSON Auto Data

分類Dev

SQL Server : 2 Stored Procedure 1 for XML & one for data

分類Dev

No process is on the other end of the pipe (SQL Server 2012)

分類Dev

SQL Server2012のRANDBETWEEN

分類Dev

Requires SQL Server 2012 Express LocalDB

分類Dev

SQL Server 2012のJSON_VALUE?

分類Dev

How to check history in SQL Server 2012?

分類Dev

Move database from SQL Server 2012 to 2008

分類Dev

SQL Server 2012 Pivot Dynamic with Values?

分類Dev

SQL Server2014とSQLServer 2012

分類Dev

authentication with node.js in SQL server 2012

Related 関連記事

ホットタグ

アーカイブ