• Find all tables that have a specified column

    by Theo Jacobs | Jul 20, 2015

     

    DECLARE
    @TblName VARCHAR(50) = NULL,
    @ColName VARCHAR(50) = 'ProcessID'
    SELECT
      tbl.name AS TableName,
      col.name AS ColumnName
    FROM sys.columns col
    LEFT OUTER JOIN sys.tables tbl ON tbl.object_id = col.object_id
    WHERE tbl.name LIKE '%' + COALESCE(@TblName,'') + '%' AND
          col.name LIKE '%' + COALESCE(@ColName,'') + '%'

     

     

     

  • Convert Dates and the available formats

    by Theo Jacobs | Jul 20, 2015

     

    SELECT '100' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 100) AS [100] UNION ALL
    SELECT '101' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 101) AS [101] UNION ALL
    SELECT '102' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 102) AS [102] UNION ALL
    SELECT '103' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 103) AS [103] UNION ALL
    SELECT '104' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 104) AS [104] UNION ALL
    SELECT '105' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 105) AS [105] UNION ALL
    SELECT '106' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 106) AS [106] UNION ALL
    SELECT '107' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 107) AS [107] UNION ALL
    SELECT '108' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 108) AS [108] UNION ALL
    SELECT '109' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 109) AS [109] UNION ALL
    SELECT '110' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 110) AS [110] UNION ALL
    SELECT '111' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 111) AS [111] UNION ALL
    SELECT '112' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 112) AS [112] UNION ALL           
    SELECT '113' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 113) AS [113] UNION ALL
    SELECT '114' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 114) AS [114] UNION ALL
    SELECT '120' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 120) AS [120] UNION ALL
    SELECT '121' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 121) AS [121] UNION ALL   
    SELECT '126' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 126) AS [126] UNION ALL
    SELECT '127' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 127) AS [127] UNION ALL
    SELECT '130' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 130) AS [130] UNION ALL
    SELECT '131' AS CNV, CONVERT(VARCHAR(50), GETDATE(), 131) AS [131]

     

     

Contact Us Now