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 February 21st, 2005, 01:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Conditional Select problem

Hi All,
I have tried several methods to try to get a field value one of two optiones based on its value.
This is what I think I should be doing, but I am not aware of the correct syntax/logic.
Code:
Select 
title,
price,

IF royalty = 10
Begin
select 'Y'
end
else
begin
Select 'N'
end

from titles
This sample is using pubs but basically I whish to make a query that will return 'Y' if the value of the field is 1 or 'N' if it is 2 or greater.

In the end I wish to order by this putting all the Y's at the end of the query

Any help would be greatly appreciated

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old February 21st, 2005, 01:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Found Solution,
Ended up using CASE insead of If/Else.
If anyone knows the sysntax for If/Else in this situation I'm still interested.



======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old September 7th, 2005, 07:37 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there a reason you can't just use a "case" statement for what you want to do? See SQL help for how.

 
Old September 7th, 2005, 07:42 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this what your looking for???
Select title,price
,test = case royalty when 10 then 'Y' else 'N' end
from titles
order by test

or is there a particular reason you want to use the word "if"?







Similar Threads
Thread Thread Starter Forum Replies Last Post
Advanced Conditional Select elite SQL Language 3 August 3rd, 2008 08:09 PM
select problem hastikeyvan SQL Server 2000 2 May 17th, 2008 03:13 AM
Conditional select previous records' value sjanderson XSLT 5 May 4th, 2007 03:28 AM
Chapter 4 Conditional Expressions Problem Jim Wile BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 June 30th, 2004 03:07 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.