无法编写SQL查询

I have a table with the following table structure and entries. I want to write a query that will give me name of the columns for a particular row whose row value is null corresponding to a particular user. Like for name = mayur i want the output as "Company Gender Citizen" but not others because their value is NULL.

Note: 1.OMIT the "Name, ID Password, Email" columns. 2. all the column name may change as the admin has the right to add or remove columns. enter image description here

Please help me writing the SQL query.

Try this:

SELECT 
  CASE WHEN Company IS NULL THEN 'Company, ' ELSE '' END
+ CASE WHEN Gender IS NULL THEN 'Gender, ' ELSE '' END
+ CASE WHEN Citizen IS NULL THEN 'Citizen, ' ELSE '' END
-- + ... -- add CASE statement for all other relevant columns
FROM Table_Name
WHERE Name = 'mayur'

You will need to clear the last comma created, but I think it is no big deal.

Try this, Just little modification in previous response

SQL SERVER version

DECLARE @query as varchar(max);
SET @query='select '+stuff((select '+'+'CASE WHEN ['+COLUMN_NAME+'] is null THEN '''+COLUMN_NAME+ ''' ELSE '''' END' from information_schema.columns where table_name = 'users' AND COLUMN_NAME not in ('Name', 'ID', 'Password', 'Email') for xml path('')),1,1,'')+' from users WHERE [name]=''mayur'' ';
execute(@query)

MySQL version

SELECT GROUP_CONCAT(CONCAT('CASE WHEN `',`COLUMN_NAME`,'` is null THEN ''',COLUMN_NAME,''' ELSE '''' END ') ) into @casestmt
FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_NAME`='users';
set @query="select @casestmt from users WHERE name='mayur'";
PREPARE stmt1 from @query;
EXECUTE stmt1;

This will generate same query which @Giorgos Altanis had suggested only difference is that column names will be automatically fetched defined for table. If you dont want to create Proc then you can execute all statement at once which will give you desired output