Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL select where 2

Status
Not open for further replies.

RosieGp

Programmer
Jun 23, 2009
83
US
Hi all,
I have sql data as following:
ID Michigan_Produce Item

0001-1 F Tea

0001-2 T Apples

0000-3 T Coffee

The query that I have right now is:

select ID, Michigan_Produce, Item
from Michigan_Produce_Table
where ID Like @IDNumber + '[-]%'

I have to modify this query to return True where it says 'T'
and False where it says 'F'...

How can I do this. Any help is appreciated..
 
Try

Code:
select ID, CASE WHEN Michigan_Produce = 'T' THEN 'TRUE' ELSE 'FALSE' END AS Michigan_Produce, Item    
from Michigan_Produce_Table
where  ID Like @IDNumber + '[-]%'

This only allows for True/False combinations. And only the true will reflect true. Everything else will be false.

Look up SQL CASE for more details.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
C#.NET Programmer
 
Try
Code:
select ID
 , Michigan_Produce
 , TrueOrFalse = case Michigan_Produce
      when 'T' then 'True'
      else 'False'
   end
 , Item    
from Michigan_Produce_Table
where  ID Like @IDNumber + '[-]%'

Good luck.

MCITP SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
 
Thank you all for you replies...
@mstrmage1768, it works perfectly.
Thanks a lot...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top