CoverYourASP --> Snippets

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
45 active users
2341 visitors today
2027 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2016 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

"Snippets" are mini-articles - they allow me to very quickly add answers to your frequently asked questions, and add brief explanations for topics that you've searched for without success. So, everytime you send an email or perform a search, chances are a new snippet will be the result!

11 Dec: Conditionally using a database field with IIF

Mark Johnson:

In using a SQL query string, can one include the value in a field IF that value is greater than NULL, like:

SELECT [First] + ' ' + [Last] + ',' + [IF [Initials>NULL]]..

Me:

Use the iif function, e.g.

SELECT [First]+' '+[Last]+','+iif(IsNull([Initials]),'',[Initials])...

IIF takes 3 parameters. First, the test that you want to perform (in this case IsNull([Initials]) ), then what to use when the test fails (in this case an empty string). Lastly, what will be used when the test passes.

Featured sponsor
My favorite resources


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?