Question: I have the following mumbers in column B

```
4025015659
4025015660
4025015661
4025015662
-266490.78
-266491.78
-266492.78
-266493.78
0
0
0

```

I need to the delete the all numbers except negative numbers. Is it possible to have a formula or vba code to do so.

Answer: 
The problem appears to have to do with the `NULL` values in some of your columns. In particular, the `SPARE1` and `SPARE2` columns can take on `NULL` values, and your intention is that such `NULL` values should equate. In the query below, I wrapped them on both sides of the join with `COALESCE`, and I am getting the expected output now.

```
SELECT B.BEN, B.Budhol, B.COCODE, B.FIELD, B.OBJ, B.SPARE1, B.SPARE2,    
    SUM(B.value) AS Value,
    Code = STUFF((SELECT ', ' + Code FROM temp2 t
                  WHERE t.BEN = B.BEN AND t.Budhol = B.Budhol AND t.COCODE = B.COCODE AND
                        t.FIELD = B.FIELD AND
                        COALESCE(t.SPARE1, '') = COALESCE(B.SPARE1, '') AND
                        COALESCE(t.SPARE2, '') = COALESCE(B.SPARE2, '')
                 FOR XML PATH('')), 1,1, '')
FROM temp2 B
GROUP BY B.BEN, B.Budhol, B.COCODE, B.FIELD, B.OBJ, B.SPARE1, B.SPARE2;

```

[![enter image description here](https://i.stack.imgur.com/oEjca.png)](https://i.stack.imgur.com/oEjca.png)

[Demo
----](http://rextester.com/KEGUH44249)
```
CREATE TABLE #Table1
    ([Budhol] int, [COCODE] int, [BEN] int, [OBJ] int, [SPARE2] varchar(4), [SPARE1] varchar(6), [TASKNO] varchar(4), [Value] int, [Field] int, [Code] varchar(100))
;

INSERT INTO #Table1
    ([Budhol], [COCODE], [BEN], [OBJ], [SPARE2], [SPARE1], [TASKNO], [Value], [Field], [Code])
VALUES
    (362103, 36, 362101, 991003, NULL, 'MA1001', NULL, 4516, 613030, 001),
    (362104, 36, 362104, 991003, NULL, 'MA1001', NULL, 9088, 613030, 002),
    (362103, 36, 362101, 991003, NULL, 'MA1001', NULL, 3387, 613030, 003),
    (362103, 36, 362101, 991003, NULL, 'MA1001', NULL, 4026, 613030, 004)

SELECT DISTINCT BUDHOL
    ,COCODE
    ,BEN
    ,OBJ
    ,SPARE2
    ,SPARE1
    ,TASKNO
    ,SUM(VALUE)VALUE
    ,FIELD
    ,STUFF((
            SELECT ','+'00' + CONVERT( VARCHAR(10),U.CODE)
            FROM #TABLE1 U
            WHERE B.BEN = U.BEN
                AND B.BUDHOL = U.BUDHOL
                AND B.COCODE = U.COCODE
                AND B.FIELD = U.FIELD
                AND B.SPARE1 = U.SPARE1

            FOR XML PATH('')
            ), 1, 1, '') AS USERLIST
FROM #TABLE1 B
GROUP BY [BUDHOL]
    ,[COCODE]
    ,[BEN]
    ,[OBJ]
    ,[SPARE2]
    ,[SPARE1]
    ,[TASKNO]
    ,[FIELD]

```

output

```
BUDHOL  COCODE  BEN OBJ SPARE2  SPARE1  TASKNO  VALUE   FIELD   USERLIST
362103  36  362101  991003  NULL    MA1001  NULL    11929   613030  001,003,004
362104  36  362104  991003  NULL    MA1001  NULL    9088    613030  002

```