1

I need to remove the xml-tags from the nested sql statement:

SELECT STUFF(
    (
        SELECT Mailbox
        FROM dbo.Mailbox
        WHERE UnitGroup IN (
            SELECT a.Groups
            FROM (
                SELECT DISTINCT ID, GroupFC AS Groups
                FROM dbo.v_Pending

                UNION ALL

                SELECT DISTINCT ID, GroupBN AS Groups
                FROM dbo.v_Pending

                UNION ALL

                SELECT DISTINCT ID, GroupRM AS Groups
                FROM dbo.v_Pending
            ) AS a
            WHERE a.Groups IS NOT NULL
            AND a.ID = 12345
        )
        FOR XML PATH('')
    ), 1, 0, ''
) AS Mails

I tried it with the statement FOR XML PATH('') but it doesn't work. Maybe someone knows the error. I always get the xml-tags -.-

Currently result looks like this:

<Mailbox>[email protected];</Mailbox>
<Mailbox>[email protected];</Mailbox>
1
  • 1
    What do you want it to return? Commented Aug 22, 2019 at 16:47

1 Answer 1

1

I found the solution for my problem. I had to add in my nested SELECT-Statement an empty string '':

SELECT STUFF(
    (
        SELECT '' + Mailbox
        FROM dbo.Mailbox
        WHERE UnitGroup IN (
            SELECT a.Groups
            FROM (
                SELECT DISTINCT ID, GroupFC AS Groups
                FROM dbo.v_Pending

                UNION ALL

                SELECT DISTINCT ID, GroupBN AS Groups
                FROM dbo.v_Pending

                UNION ALL

                SELECT DISTINCT ID, GroupRM AS Groups
                FROM dbo.v_Pending
            ) AS a
            WHERE a.Groups IS NOT NULL
            AND a.ID = 12345
        )
        FOR XML PATH('')
    ), 1, 0, ''
) AS Mails
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.