I am using MSSQL. How can I do appear or disappear a column according to column value?
I thought using CASE statement, but It wasnt.
Please help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Within a single
selectstatement, you can’t make a column disappear; the number and name of columns are fixed by theselectclause. However, you can overwrite the value of a column in the output, which is where you would typically use acase,nullif, orcoalesceexpression. For example:In this case, col3 is still going to be in the output, but its value will be null if it meets certain conditions specified in the case statement.
If you really don’t want the column to be there at all, then you will need to write multiple
selectstatements and choose which one to execute. For example:That’s an unusual construction. It’s really more common to allow the column to appear in the output and simply overwrite its value.