Solved

SQL display column name with condition

Posted on 2016-09-26
3
40 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 28

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 69

Accepted Solution

by:
Scott Pletcher earned 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Character matching different date formats for dates between 6 44
SQL Help 27 40
always on switch back after failover 2 31
TSQL query to generate xml 4 31
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now