Hi,
I'm using SQL server 2005.
I have below query and table.
I'm trying to get all rows into just one row by excluding everything that is NULL and showing the rig numbers (the numbers in the last column) one after another seperated with a "|".
I know it can be done as i got it before but in the below query something is wrong and I cannot figure it out.
Would anyone be able to advise?
Much appreciated.
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 26
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 12
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 3
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 31
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 58
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 26
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 34
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 33
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 3
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 10
I'm using SQL server 2005.
I have below query and table.
I'm trying to get all rows into just one row by excluding everything that is NULL and showing the rig numbers (the numbers in the last column) one after another seperated with a "|".
I know it can be done as i got it before but in the below query something is wrong and I cannot figure it out.
Would anyone be able to advise?
Much appreciated.
Code:
SELECT i.FMTITEMNO,i.ITEMDESC, STUFF
((SELECT ' | ' + rtrim(g.ACSEGVAL03)
FROM GLAMF AS g
WHERE ISNUMERIC(g.ACSEGVAL03) =1 AND i.GLACCT=g.ACCTFMTTD FOR XML PATH(''), TYPE ).value('.', 'varchar(max)'), 1, 3, '') AS RigNumber
FROM IFSHIPD AS i
WHERE i.FMTITEMNO='2-07-24-43-02748' --AND ISNUMERIC(g.ACSEGVAL03) =1
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 26
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 12
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 3
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 31
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 58
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 26
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 34
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 33
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | NULL
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 3
2-07-24-43-02748 | Fittings Poly 1 1/4" 50mm | 10