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

  • That will return all tables with suffix YYYYMM where YYYYMM represent every month of the current calendar quarter.

    SELECT t.name

    FROM sys.tables t

    JOIN (SELECT '%' + CAST(QFM + m AS VARCHAR) AS QM

    FROM ( SELECT CAST(YEAR(GETDATE()) AS VARCHAR(4))

    + RIGHT('0' + CAST(DATEPART(QUARTER,GETDATE()) * 3 AS VARCHAR(2)),2) AS QFM ) q

    CROSS JOIN (SELECT 0 m UNION ALL SELECT 1 m UNION ALL SELECT 2 m) m

    ) qm3

    ON t.name LIKE qm3.QM

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]