检查所有列的空格

时间:2018-04-10 17:45:58

标签: sql teradata

我想检查所有列,看看是否有任何记录只返回空格。目前,我正在检查它:

SELECT COLUMNNAME FROM TABLE WHERE COLUMNNAME = ''

但是,我需要检查多个表,每个表包含很多列。我宁愿不一次检查每个列,有没有办法让查询检查表中的所有列?

1 个答案:

答案 0 :(得分:1)

你可以编写一个SQL语句来吐出你所追求的sql语句。有时我只是在excel中转​​储列列表,并在我感觉特别懒的时候将sql语句拼接在一起。

WITH cteTable AS 
(
    SELECT columnid, columnname, tablename, databasename 
    FROM "DBC".ColumnsV 
    WHERE TableName = 'yourtablename' AND DatabaseName = 'yourdatabasename'
)
SELECT output 
FROM
(
    SELECT DISTINCT CAST(1 AS INTEGER) AS myorder, 'SELECT * FROM ' || DatabaseName || '.' || TableName || ' WHERE ' AS output
    FROM cteTable
    UNION ALL
    SELECT columnid, CASE WHEN ROW_NUMBER() OVER (ORDER BY ColumnId) > 1 THEN 'OR ' ELSE ' ' END || columnname || ' = '''''
    FROM cteTable
) sub 
ORDER BY myorder    

这并没有考虑字段类型或类似的任何东西,但它应该让你在球场