jeudi 28 juillet 2016

Write the query without Temp

But I need simple way using joins

DECLARE @ID uniqueidentifier
    SELECT @ID ='000000910035';
    WITH temp AS(

            SELECT  *
            FROM    BB
            WHERE   MId =  @ID
            UNION ALL
            SELECT  t.*     FROM    BB t INNER JOIN temp r ON t.PaId = r.MId
    )

    SELECT  *
    FROM    temp

Aucun commentaire:

Enregistrer un commentaire