The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Determining if a T-SQL variable is in a range of values

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Darrell Norton

Posts: 876
Nickname: dnorton
Registered: Mar, 2004

Darrell Norton is a consultant for CapTech Ventures.
Determining if a T-SQL variable is in a range of values Posted: Oct 6, 2004 4:09 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Darrell Norton.
Original Post: Determining if a T-SQL variable is in a range of values
Feed Title: Darrell Norton's Blog
Feed URL: /error.htm?aspxerrorpath=/blogs/darrell.norton/Rss.aspx
Feed Description: Agile Software Development: Scrum, XP, et al with .NET
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Darrell Norton
Latest Posts From Darrell Norton's Blog

Advertisement

Here’s a neat little T-SQL trick.

You can use set-based operations on variables. For example, copy this in SQL Server Query Analyzer and running it prints “Vowel” to the output window:

DECLARE @letter char(1)
SELECT @letter = 'A'
IF @letter IN ('A', 'E', 'I', 'O', 'U')
            PRINT 'Vowel'
ELSE
            PRINT 'Consonant'

Yes the example is simple, but where I find it useful is with a varchar variable passed into a stored proc called by other stored procs. I need to check for one of 10 values (out of hundreds), and this is a whole lot easier than writing
IF @letter = ‘A’ OR @letter = ‘E’ etc.


This Blog Hosted On: http://www.DotNetJunkies.com/

Read: Determining if a T-SQL variable is in a range of values

Topic: Xamlon Goes 1.0 Previous Topic   Next Topic Topic: Keywords to Search .NET Related Knowledge Base Articles

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use