Search
 
SCRIPT & CODE EXAMPLE
 

SQL

how to find columns with null values in sql

declare @col varchar(255), @cmd varchar(max)

DECLARE getinfo cursor for
SELECT c.name FROM sys.tables t JOIN sys.columns c ON t.Object_ID = c.Object_ID
WHERE t.Name = 'ADDR_Address'

OPEN getinfo

FETCH NEXT FROM getinfo into @col

WHILE @@FETCH_STATUS = 0
BEGIN
    SELECT @cmd = 'IF NOT EXISTS (SELECT top 1 * FROM ADDR_Address WHERE [' + @col + '] IS NOT NULL) BEGIN print ''' + @col + ''' end'
    EXEC(@cmd)

    FETCH NEXT FROM getinfo into @col
END

CLOSE getinfo
DEALLOCATE getinfo
Comment

PREVIOUS NEXT
Code Example
Sql :: what is subquery in sql 
Sql :: grapgql 
Sql :: window function sql 
Sql :: sql average 
Sql :: update sql 
Sql :: sql query print strings and int 
Sql :: sql quary intervewi question 
Sql :: mariadb cast null to 0 
Sql :: find in set in postgresql 
Sql :: mysql set column equal to another automatic 
Sql :: SQL Switch Databases 
Sql :: sql like with multiple values 
Sql :: mamp mysql password 
Sql :: how to install mysql workbench in ubuntu 20.04 
Sql :: oracle tablespace autoextend 
Sql :: to_sql pandas 
Sql :: sql change primary key to composite key 
Sql :: sql join 3 tables 
Sql :: not in in mongodb 
Sql :: xampp reset mysql 
Sql :: error code 1241 mysql 
Sql :: postgres where 
Sql :: Why mysql is used? 
Sql :: nested query 
Sql :: mysql login 
Sql :: sql offfset 
Sql :: use mysql in java program 
Sql :: sql select all 
Sql :: sql update from two different database 
Sql :: homebrew nysql launch 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =