question

talveen avatar image
talveen asked

I want to find all the columns in my table which have value '1'.

I want to find all the columns in my table which have value '1'. i have a table which has various columns [form fields], in this table I am also specifying whether it should be editable/shown. If the value is '1' for "ShowProcess" ; it means the column process is shown in UI. Now I want all the columns in which the value is '1' based on a column called processID
pivot
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Please clarify your question with an example. Are you trying to do this through a SELECT statement?
0 Likes 0 ·

1 Answer

· Write an Answer
Grant Fritchey avatar image
Grant Fritchey answered
In general, it's best to not think of queries based on selectively picking columns. You filter rows worth of data. Then, if you want to format the output, you do that in the client. So you have a processID column that you want to return all values of 1 for it, and all your other columns, which you can then decide which get displayed later. SELECT mt.* FROM dbo.MyTable AS mt WHERE mt.processID = 1;
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thank you for the reply Grant. The issue I am facing is that, as I had mentioned, the master table contains the value/properties of various columns. Based on their value [1,0]; it will be shown or will be editable in UI. The query you mentioned will give me all the records where the processId is 1. But my requirement something else, my table has a unique key called processID, every processID will have different columns like below ProcessID ProcessName EditProcess ShowProcess EditPriority ShowPriority ---------------------------------------------------------------------------- A test 0 1 1 1 There are 22 columns like this; i have provided just a snippet. Now I need all the column names which have value '1' where he processID is 'A'. Once I have the columns I need to map to it other set of tables to get the desired result. I hope this give you a clear picture of support I actually need.
0 Likes 0 ·
So what you're saying is that one table has a listing of columns for selecting data from other tables? That's a very problematic design. The only way you can combine the results of a query with a SELECT statement like this would be to use ad hoc SQL. You really can't combine these within a T-SQL statement without generating it by building it with IF/THEN or CASE statements.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.