Home TSQL add all data to first row then half the data after
Reply: 0

TSQL add all data to first row then half the data after

user3672
1#
user3672 Published in June 19, 2018, 6:19 pm

Hey all I have a table that when I run the query I get something like this:

ID |The GUID                 |Quantity |Maint Part Number |Ship Group    |Date Received
-----------------------------------------------------------------------------------------
2  |54219-8974-8702-852-5425 |50       |54VRT             |ShipG105      |06/08/2018
3  |68v3f-5kjd-46ee-586-5988 |10       |M6eR5w            |ShipG001      |10/19/2010
4  |ErR20-bvmd-0001-bGT-0O0O |100      |MRE101            |ShipG99       |01/01/2011

Now what I am looking to want to do is this:

ID |The GUID                 |Quantity |Maint Part Number |Ship Group    |Date Received
-----------------------------------------------------------------------------------------
2  |54219-8974-8702-852-5425 |50       |54VRT             |ShipG105      |06/08/2018
3  |                         |         |M6eR5w            |ShipG001      |10/19/2010
4  |                         |         |MRE101            |ShipG99       |01/01/2011

ALL the data is present on this first record row while the following rows only have the adition data of inv_....

I'm getting all this data from multipole INNER JOIN tables and also LEFT JOIN tables.

A Query example:

SELECT
   BL.ID                AS 'ID',
   BL.guid              AS 'The GUID',
   BL.qty               AS 'Quantity',
   I.inv_maintPartNum   AS 'Maint Part Number',
   I.inv_ShipGrp        AS 'Ship Group',
   I.inv_DateRec        AS 'Date Received' 
FROM 
   BizLine              AS BL 
INNER JOIN inventory    AS I 
   ON BL.ID = I.ID
..........

How can I do this?

UPDATE

If I have more records that are of a different ID that looks like this:

ID |The GUID                 |Quantity |Maint Part Number |Ship Group    |Date Received
-----------------------------------------------------------------------------------------
2  |54219-8974-8702-852-5425 |50       |54VRT             |ShipG105      |06/08/2018
2  |68v3f-5kjd-46ee-586-5988 |10       |M6eR5w            |ShipG001      |10/19/2010
2  |ErR20-bvmd-0001-bGT-0O0O |100      |MRE101            |ShipG99       |01/01/2011
3  |68rGw-3567-0001-123-fG34 |5        |GRD2859           |ShipG1        |11/11/2012
3  |5879R-376T-FDSW-RT7-23FG |1005     |Sv22              |ShipG87       |04/19/2017

And now using the query from @SQLChao it looks like this:

2  |54219-8974-8702-852-5425 |50       |54VRT             |ShipG105      |06/08/2018
2  |                         |         |M6eR5w            |ShipG001      |10/19/2010
2  |                         |         |MRE101            |ShipG99       |01/01/2011
3  |                         |         |GRD2859           |ShipG1        |11/11/2012
3  |                         |         |Sv22              |ShipG87       |04/19/2017

Now what it should look like is this:

2  |54219-8974-8702-852-5425 |50       |54VRT             |ShipG105      |06/08/2018
2  |                         |         |M6eR5w            |ShipG001      |10/19/2010
2  |                         |         |MRE101            |ShipG99       |01/01/2011
3  |68rGw-3567-0001-123-fG34 |5        |GRD2859           |ShipG1        |11/11/2012
3  |                         |         |Sv22              |ShipG87       |04/19/2017

Notice how ID 3 starts with all the data just like the first ID 2 does and then only shows the other data thereafter.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338811 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO