Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2008, 03:46 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default SELECT IF ... HELP Please.

Is it even possible to do a if statement in a select? If so how would I get this to work??

I know this doesn't work, but if it can be fixed please so me the correct syntex.

select if(LAST_NAME = 'SMITH' then 'JONES' else LAST_NAME), PHONE_NUMBER, ZIPCODE from T_ADDRESS


Thanks...

 
Old January 21st, 2008, 04:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The CASE expression will do what you want:

select case when LAST_NAME = 'SMITH' then 'JONES' else LAST_NAME end as LastName, PHONE_NUMBER, ZIPCODE from T_ADDRESS

Jeff Mason
[email protected]
 
Old January 21st, 2008, 05:29 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

THANK YOU!!! I knew it was possible because I had done it in the past, but I haven't worked in SQL so long, I forgot about CASE.

THANKS AGAIN..






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
select="node1", select="node2"... Baldo XSLT 7 March 12th, 2004 10:38 AM
Select Within A Select Problem vinyl-junkie Classic ASP Databases 6 June 7th, 2003 04:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.