|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Exellent, thanks alot, didn't even think of going about it in that way...
|
|
#4
|
|||
|
|||
|
I belive that you can use the Case Statment:
CASE WHEN [tblErrors].[RepairDate]<=[tblErrors].[RequiredRepair] THEN 'True' ELSE 'False' END As On Time |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Help with a view |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|