Solved

SQL display column name with condition

Posted on 2016-09-26
3
34 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 18

Expert Comment

by:Pawan Kumar Khowal
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:
ScottPletcher 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 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

12 Experts available now in Live!

Get 1:1 Help Now