Click here to Skip to main content
15,614,809 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi All
I need to hide a particular Column Name from the result table but that datas should be stored in the Database.Should not be deleted,but Just it should be Invisible.

What I have tried:

Since i am new to sql i need proper Guidance from the experts here.Please Solve my query
Posted
Updated 28-Dec-22 18:56pm

Don't list it in the SELECT statement.
Instead of doing
SQL
SELECT * FROM MyTable
List only the columns You want to see:
SQL
SELECT ColumnIWant, OtherColumnIWant, LastColumnIWant FROM MyTable
You should get into the habit of doing this anyway: never retrieve columns you don't need (it's inefficient and can take a lot of bandwidth if you aren't careful) - and it can make your code more robust, in that it can cope with changes to the DB table without needing changes.
 
Share this answer
 
Comments
Maciej Los 23-Aug-16 16:09pm    
5ed!
Explicitly define the fields you want back rather than using "select *" which is something you should do anyway

SQL
Person
------
ID, Name, EmailAddress


SQL
SELECT ID, Name FROM Person


The above will create a result set with just ID and Name, not EmailAddress.
 
Share this answer
 
Comments
Maciej Los 23-Aug-16 16:09pm    
5ed!
I need to declare the column, but I need to hide it.
 
Share this answer
 
Microsoft needs to add a native function in T-SQL to exclude columns in a SELECT query when using a wildcard.

SELECT *,-t.[RecordID],-t.[Date] FROM dbo.sometable t

I'm selling the movie rights to Star Wars for free!
 
Share this answer
 
Comments
Richard Deeming 29-Apr-21 4:18am    
No, lazy developers need to stop using SELECT * when they don't actually want all columns!

Your fictional syntax example is not a "solution" to this already-solved question from 2016.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900