Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Displaying text based on true/false

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-09 : 12:12:28
I have a varchar column with true or false values. The query was like
SELECT....isnull(MemberPlotLinks.Member, 'No')...
And the output was True or False.
Instead I want to display [Member] if it is true, nothing if false.

How do I do that?
Thanks.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-07-09 : 12:15:26


Select case when col1 is 'true' then Member else '' end from table

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-09 : 12:26:27
But I have other columns in the query like
SELECT FirstName + ' ' + LastName + ' ' + IsNull(MemberPlotLinks.Member, 'No')
So, how I do it?
Thanks.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-09 : 12:33:28
PLEASE

SHOW EXAMPLE DATA

AND

WANTED OUTPUT

That would really help to help you


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-09 : 12:37:35
SELECT FirstName + ' ' + LastName + ' Member: ' + IsNull(MemberPlotLinks.Member, 'No')

current output: Kelly Hops Member: True

desired output: 1. Kelly Hops [Member]
2. Fred Thompson
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-09 : 12:47:01
Do you mean this?

SELECT
FirstName + ' ' +
LastName +
case
when MemberPlotLinks.Member is null then ''
when MemberPlotLinks.Member = 'false' then ''
else '[Member]'
end
.
.
.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-09 : 13:35:43
Thanks, its working...didn't know I can use case right after the plus.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-10 : 03:00:30
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -