|
my query resultset has three columns boolean1, boolean2, boolean3 i want to get the names of the columns for which value is true select where boolean1 or boolean2 or boolean3
(comments are locked)
|
|
That is not exactly how TSQL works. You request column names and the values that are stored in those columns where certain predicates are met. You could use something like this to see what values you have in your table(s)
(comments are locked)
|
|
My post here doesn't answer the OP's question. I just wanted to show you a trick so you don't have to type as much to make test data nor wait as long while it develops. ;-) It'll also run in a flash compared to the While Loop. The following creates 100,000 rows in the proverbial blink of an eye. Try the same thing with your loop. @Jeff I must admit I read @Fatherjack's query with an eyebrow raised...
Jul 19 '11 at 02:07 PM
ThomasRushton ♦
@Jeff Moden - Thanks Jeff. I know the loop is ugly and I'm not wholly sure why I went with it. I dont generally create more than a few rows and almost always go for @ThomasRushton - today I will do something to raise the other eyebrow and tomorrow we will give them both a workout :) I'll leave the answer "as is" so that people have the chance to compare the options.
Jul 20 '11 at 01:01 AM
Fatherjack ♦♦
Thank you, good Sir, for the congrats on the nomination. Understood on the loop and thank you for the feedback there.
Jul 26 '11 at 07:26 PM
Jeff Moden
(comments are locked)
|
|
What about the
(comments are locked)
|


Have you got sample code that you've used so far?
@dileepmgu If you need to get the list of columns for each record, but that list should only include those columns for which the value is true while selecting a record is based on the condition that any of these is true then (assuming that your columns are actually of a bit data type):
select rtrim( case when boolean1 = 1 then 'boolean1 ' else '' end + case when boolean2 = 1 then 'boolean2 ' else '' end + case when boolean3 = 1 then 'boolean3' else '' end) List from YourTable where boolean1 = 1 or boolean2 = 1 or boolean3 = 1;The above will return a space-delimited list of those columns per record which personally have the value of 1. Who knows, maybe this is what you are asking, but I am not really sure what is the purpose of such a selection :)