• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 64
  • Last Modified:

SQL display column name with condition

Hi,

I know sql can display column name of a table by using this

select Column_name
from Information_schema.columns
where Table_name like 'myTable'

There are over 200 fields in this table, but I do not want to display all the fields to the users. What would be the best way to do this?  thanks
0
mcrmg
Asked:
mcrmg
1 Solution
 
Pawan KumarDatabase ExpertCommented:
provide column names.

select [col_1],[col_2]...................etc 
from Information_schema.columns 
where Table_name like 'myTable'

Open in new window

0
 
Scott PletcherSenior DBACommented:
Create a new table that has the columns you do want to show to users.  This could be based on column name, data type or whatever other condition you want.  Then join sys.columns (not information_schema views, which are slow, cause blocking/locking and do not have a lot of data) to the new table to select the specific columns to list for each table.

Finally, you can use dynamic SQL or a static view that is created dynamically based on the new table to give the actual data to the users.
0
 
mcrmgAuthor Commented:
thank you
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now