Home Forums SQL Server 2008 T-SQL (SS2K8) Finding a table with date appended to it and check for the range of that date RE: Finding a table with date appended to it and check for the range of that date

  • Another way to get the table names...

    SELECT st.Name

    FROM sys.tables st

    WHERE RIGHT(st.Name,6) IN

    (

    SELECT CONVERT(CHAR(6), DATEADD(mm,t.N,DATEADD(qq,DATEDIFF(qq,0,GETDATE()),0)), 112)

    FROM (SELECT 0 UNION ALL SELECT 1 UNION ALL SELECT 2) t (N)

    )

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)