Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 7th, 2005, 09:40 AM
Fowler_ko Fowler_ko is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 277 Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 10 h 24 m 33 sec
Reputation Power: 84
Help with a view

I am very new to SQL server. At the moment just having a play around and trying to transfer a DB I made in Access onto SQL Server 2000. Then use an Access Project to link to it and create all the forms. Everything is going fine apart from the following:

In my old Access DB I had a query with the following code in the SELECT section of the SQL. This gave me a list of Boolean values depending on whether or not [RepairDate] is lower than [RequiredRepair]

IIf([tblErrors].[RepairDate]<=[tblErrors].[RequiredRepair],True,False) AS OnTime

When using the same SQL in SQL Server Views this give an error. Could someone please point me in the right direction to recreate this in SQL Server?

Thanks

Reply With Quote
  #2  
Old April 9th, 2005, 02:15 AM
gregory.owen@hp's Avatar
gregory.owen@hp gregory.owen@hp is offline
Maniac
ASP Free Novice (500 - 999 posts)
 
Join Date: Sep 2003
Location: Sweet Home, Oregon
Posts: 548 gregory.owen@hp User rank is Sergeant (500 - 2000 Reputation Level)gregory.owen@hp User rank is Sergeant (500 - 2000 Reputation Level)gregory.owen@hp User rank is Sergeant (500 - 2000 Reputation Level)gregory.owen@hp User rank is Sergeant (500 - 2000 Reputation Level)gregory.owen@hp User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 4 h 37 m 8 sec
Reputation Power: 14
I can't find any reference to using IIF in select statements except in the case of MDX (Multidimensional Expressions).

You can achieve the same result by unioning the trues with the falses in two separate queries:

Select 'True' as OnTime from tblErrors
where tblErrors.RepairDate<=tblErrors.RequiredRepair
UNION
Select 'False' as OnTime from tblErrors
where tblErrors.RepairDate>tblErrors.RequiredRepair

Note: If you put this into the query builder tool it will complain that it doesn't support the "Union" keyword, but if you open the view's properties window and put it in there, it works just fine.

Reply With Quote
  #3  
Old April 11th, 2005, 06:22 AM
Fowler_ko Fowler_ko is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Cumbria, UK
Posts: 277 Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level)Fowler_ko User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 5 Days 10 h 24 m 33 sec
Reputation Power: 84
Exellent, thanks alot, didn't even think of going about it in that way...

Reply With Quote
  #4  
Old April 15th, 2005, 11:33 AM
akinator akinator is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 7 akinator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 39 m 55 sec
Reputation Power: 0
I belive that you can use the Case Statment:

CASE
WHEN [tblErrors].[RepairDate]<=[tblErrors].[RequiredRepair]

THEN 'True'
ELSE 'False'

END As On Time

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Help with a view


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT