• Sure:

    Both blocks of code are formatted the same when pasted into the forum. The bottom block is wrapped in <PRE> </PRE>

    Code taken from another thread:

    SELECT a.*,

    (CASE WHEN (SELECT TOP 1 b.effDate-1

    FROM #table b

    WHERE b.effDate > a.effDate AND a.currencycode = b.currencycode) IS NULL

    THEN (SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE())+1, -1))

    ELSE (SELECT TOP 1 b.effDate-1

    FROM #table b

    WHERE b.effDate > a.effDate and a.currencycode = b.currencycode)

    END) AS 'discDate'

    FROM #table a

    SELECT a.*,
        (CASE WHEN (SELECT TOP 1 b.effDate-1 
                    FROM #table b 
                    WHERE b.effDate > a.effDate AND a.currencycode  =  b.currencycode) IS NULL
         THEN  (SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE())+1, -1))
         ELSE (SELECT TOP 1 b.effDate-1
               FROM #table b
               WHERE b.effDate > a.effDate and a.currencycode = b.currencycode) 
         END)  AS 'discDate'
    FROM #table a
    

    It should look like this in the source window

    <PRE>

    SELECT a.*,
        (CASE WHEN (SELECT TOP 1 b.effDate-1 
                    FROM #table b 
                    WHERE b.effDate > a.effDate AND a.currencycode  =  b.currencycode) IS NULL
         THEN  (SELECT DATEADD(mm, DATEDIFF(mm, 0, GETDATE())+1, -1))
         ELSE (SELECT TOP 1 b.effDate-1
               FROM #table b
               WHERE b.effDate > a.effDate and a.currencycode = b.currencycode) 
         END)  AS 'discDate'
    FROM #table a
    

    </PRE>

    SQL guy and Houston Magician