Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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 October 17th, 2007, 01:01 AM
Authorized User
 
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Evaluating IF something is in a list

I have a function that checks if the input @InDate is a weekend by using IF DATEPART(dw, @InDate) is equal to 1 or 7, then returning true or false.

I can get it to work using two separate comparisons, IF DATEPART(...) = 1 OR DATEPART(...) = 7, but I also know a normal SELECT can use something like
SELECT column FROM table WHERE column IN (1,7)

That's a nice easily readable way of checking for a variety of values (as opposed to the alternative WHERE column = 1 OR column = 7 OR column = ...).

Can I make IF condition "set based" like that?

 
Old October 17th, 2007, 08:57 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Have you tried it yet?

This works:

IF 0 IN (0,2,3,4)
   PRINT 'Yup'


-Peter
 
Old October 17th, 2007, 05:37 PM
Authorized User
 
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Aw man... I had tried several ways and it was giving me some error (didn't write it down), but I just tried again and it's working.

Gotta love them PEBKAC errors (=

Thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM
List tablesname from database & list databasename ittorget MySQL 3 September 10th, 2005 03:06 AM
Evaluating body content of a custom tag Tag Librarian Pro JSP 0 May 13th, 2005 02:40 PM
Evaluating Textbox in Realtime without postback mahulda ASP.NET 1.0 and 1.1 Basics 5 March 10th, 2004 03:52 AM





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