Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 31st, 2008, 03:06 PM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default IF statement in SQL Pass Through Query

I am writing a pass through query to SQL.

Since the query is performed by SQL Server, does anyone know how to write the equivalent of an IIF or If then statement in the query?

With Jet database I would state something like:
SELECT IIF([Job Name] = "Stoney Creek","Yes","No") AS Job Exists
FROM MasterJobs;

If there is anything close that would deliver the same results it would help me out a ton.

Thanks,
Coby.

 
Old January 31st, 2008, 11:48 PM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

SELECT CASE WHEN [Job Name] = 'Stoney Creek' THEN 'Yes' ELSE 'No' END AS Job_Exists FROM MasterJobs

urt
 
Old February 1st, 2008, 10:10 PM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked! Perfect.

I like that method a lot.
Thanks for your help and have a good weekend.
Coby.

 
Old February 15th, 2008, 09:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Yes, a question, Cory. Do you really want the strings "Yes" and "No" or do you want actual boolean values of yes/true/-1 and no/false/0? If so, you want

SELECT CASE WHEN [Job Name] = 'Stoney Creek' THEN True ELSE False END AS Job_Exists FROM MasterJobs


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass Table Name as a parameter in SQL query visualbrin Reporting Services 1 October 13th, 2006 04:08 PM
Not able to pass the combo box value to SQL query sparsh2010 Access VBA 3 July 26th, 2006 07:10 AM
How can I pass sql query through vb.net to crystal sachinbashetti Crystal Reports 0 May 14th, 2005 01:47 AM
Pass-Through SQL Insert Query bmwbear Access 1 October 18th, 2004 12:43 AM
SQL statement for query vickriz Access 4 September 24th, 2003 10:16 PM





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