Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL display column name with condition

Posted on 2016-09-26
3
Medium Priority
?
61 Views
Last Modified: 2016-09-26
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
Comment
Question by:mcrmg
3 Comments
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41816360
provide column names.

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

Open in new window

0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 41816361
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
 

Author Closing Comment

by:mcrmg
ID: 41816370
thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question