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 March 3rd, 2004, 06:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default Access to SQL (IIF)

Can somebody help me out with a bit of a problem I'm having with a query conversion.

I've got a query in Access that I want to make into a view on the server, but since SQL Server doesn't like IIF, it's making life a bit hellish.

Basically, this is the statement I need to fix.

IIf(Table1.AdmDate>Table2.AdmDate-0.25 And Table1.AdmDate<Table2.AdmDate,Table1.AdmDate,Table 2.AdmDate)

I thought it would be:

CASE Table1.AdmDate
    WHEN >Table1.AdmDate-0.25 AND
    <Table2.AdmDate Then Table1.AdmDate
    ELSE Table2.AdmDate
END

Basically what I'm wanting to happen is this:
If Table1.AdmDate is up to 6 hours before Table2.AdmDate, then return Table1.AdmDate, otherwise, return Table2.AdmDate

Any help would be appreciated

I am a loud man with a very large hat. This means I am in charge
__________________
<hr noshade size=\"1\"><i><font color=\"blue\">I am a loud man with a very large hat. This means I am in charge</i></font id=\"blue\">
 
Old March 3rd, 2004, 07:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try something like this:
Code:
select a.id, CASE WHEN datediff(hh, a.date1, b.date2) < 6 THEN a.date1 ELSE b.date2 END 'a_date' from t_Date1 a inner join t_date2 b on a.id = b.id
I threw this together very quickly so it may not be exactly right, however it should point you in the right direction.

Rand
 
Old March 3rd, 2004, 10:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Rand,
I eventually figured it out:
Code:
CASE WHEN 
    Table1.AdmDate > Table2.AdmDate - 0.25 AND 
    Table1.AdmDate < Table2.AdmDate 
THEN 
    Table1.AdmDate         
ELSE                       
    Table2.AdmDate END AS AdmitDate


However, getting that to work inside a user defined function is a story for another thread :)
Steven

I am a loud man with a very large hat. This means I am in charge





Similar Threads
Thread Thread Starter Forum Replies Last Post
Iif statement in Access rangeview Access 7 March 28th, 2006 01:14 PM
Is there an IIF Function in SQL Server? treadmill Classic ASP Professional 4 January 17th, 2005 06:57 AM
SQL Access/ASP.NET data access issue saeta57 SQL Server ASP 1 July 4th, 2004 04:29 PM
SQL Access/ASP.NET data access issue saeta57 Classic ASP Databases 1 July 4th, 2004 03:32 PM
IIF Expression in Access mickhumph Access 1 November 21st, 2003 02:48 PM





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