Home > database >  How about BOM's problem
How about BOM's problem

Time:04-28

Using SQL 2008 version, has query result:

Bom_no name_c name_w
B1210000003 - & gt; FPA - PVL100201 SSD253455
C1130050010 - & gt; P650XS2I0-01 FPA - PVL100201
C1130050410 - & gt; PVL1003-01 FPA - PVL100201

Hope to get the result is like this:

C1130050010 - & gt; P650XS2I0-01 FPA - PVL100201 SSD253455
C1130050410 - & gt; PVL1003-01 FPA - PVL100201 SSD253455

How do I can achieve? Have no idea,

CodePudding user response:

Left to join switch

CodePudding user response:

 USE tempdb for 
GO
IF OBJECT_ID (' dbo. [t]) IS NOT NULL
DROP TABLE dbo. [t]
GO
The CREATE TABLE dbo. [t] (
[bom_no] NVARCHAR (MAX)
, name_c NVARCHAR (MAX)
, name_w NVARCHAR (MAX)
)
GO
SET NOCOUNT ON
INSERT INTO dbo. [t] VALUES (N 'B1210000003 - & gt; ', N 'FPA - PVL100201', N 'SSD253455')
INSERT INTO dbo. [t] VALUES (N 'C1130050010 - & gt; ', N 'P650XS2I0-01', N 'FPA - PVL100201')
INSERT INTO dbo. [t] VALUES (N 'C1130050410 - & gt; ', N 'PVL1003-01', N 'FPA - PVL100201')
- above table for the test data and test -

SELECT A. *, b. [name_w]
The FROM t AS A INNER JOIN t AS B
ON a. [name_w]=B.n ame_c


CodePudding user response:

I reckon this problem won't be so simple, could be LEFT JOIN many times, and the difficulty in don't know whether to be LEFT JOIN several times

CodePudding user response:

The
__ as reference to the building road people reply:
how do I can achieve? Have no idea,


Recursive query method, the source of data table didn't you put out, not write to you,

CodePudding user response:

reference 3 floor kun jins kao kun jins kao response:
I think this problem won't be so simple, could be LEFT JOIN many times, and the difficulty in don't know whether to be LEFT JOIN several times


If the level is infinite, use cte recursion, put all have to value the relations in a field, and then cut the split, turn again, according to the maximum output column

CodePudding user response:

refer to fifth floor illiterate old gu response:
Quote: refer to the third floor kun jins kao kun jins kao response:
I think this problem won't be so simple, could be LEFT JOIN many times, and the difficulty in don't know whether to be LEFT JOIN several times


If the level is infinite, use cte recursion, put all have to value the relations in a field, and then cut the split, turn again, can be output by the largest column

Recursive union words can only seem to make these fields together, and then press the patchwork fields split into multiple lines, but then turned column can not be with the pivot line
My train of thought is spliced dynamic SQL, count out of a total of how many times to join, and then the cycle of the join on a.n ame_c=b.n ame_w spliced into the dynamic SQL, but think you very trouble
  • Related