Reputation: 713
How to avoid a column if it contains null without mentioning its name
select * from
ExmGp a
inner join
ExmMstr b
on a.ETID = b.EID
inner join
ExmMrkntry c
on b.AcYear = c.Acyear
I am trying to join three different tables like the above code but in result some of the columns are null. is it possible to avoid them using where condition?
thanks in advance
Upvotes: 1
Views: 178
Reputation: 1269443
No, but it is important that you understand the reason why.
The WHERE
clause filters rows out of the result set not columns. So, what you are asking is not supported by WHERE
or anything else.
Importantly, a SQL query returns data in a tabular format. This format specifies the columns in the result set. These columns cannot be dynamic; they are fixed for the query (unless you construct a string to execute the query).
So, you are "stuck" with all the columns specified in the SELECT
. I would recommend that you list each of the columns that you want rather than using SELECT *
.
Upvotes: 1
Reputation: 400
No there is no built-in language construct in TSQL to directly check for NULLs anywhere in the row. There are a number of workarounds though.
See this question for possible solutions How to count in SQL all fields with null values in one record?
Upvotes: 1