473,466 Members | 1,405 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Migrating Access to SQL "IIF Statement" Issue

53 New Member
Hi Guys,

I am a bit of a newbie in these things, and need a little guidance to nudge me in the right direction.

I am having a bit of a problem getting my head around this one, I am attempting to Migrate an MS Access 2003 DB to MS SQL 2005 Express and Access 2003 as the Front End.

I need to Phase out the Value of a Cost Centre around the Months it is valid, ie if the Value is 150,000 and starts in june and finishes in september, it will divide the value by 4 and present the values into Fields named jun through to sept.

[CTRStartDate] and [CTRStopDate] are Date Fields in a table tblCTR.
[CTRRESValue] holds a line value associated with the Record in tblCTR.

I have placed the code into an unbound textbox, but it is very slow, and takes 2 mins to appear on screen with 3,500 Records in tblCTR.

In the Access DB I have a query set up to present this information on screen (see the following code)

Expand|Select|Wrap|Line Numbers
  1.  (Expression) Jan =IIf((1 Between DatePart("m",[CTRStartDate]) And DatePart("m",[CTRStopDate])),DSum("CTRRESValue","tblCTRResource","[CTRID]=" & [CTRID])/((DatePart("m",[CTRStopDate])-DatePart("m",[CTRStartDate]))+1))
Is there some way to do this in SQL?

TYVMIA



Leon
May 26 '08 #1
2 2114
Echidna
53 New Member
I finally got it.

Expand|Select|Wrap|Line Numbers
  1. CASE WHEN 1 BETWEEN datepart(m , tblCTR.CTRStARTDate) AND datepart(m , tblCTR.CTRStopDate) THEN tblCTR.CTRValue / (datepart(m , tblCTR.CTRStopDate) - datepart(m , tblCTR.CTRStartDate) + 1) ELSE NULL END
Cheers

Leon
May 28 '08 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Nice one Leon. This is not too easy in T-SQL as you've probably found out by now, so thanks for posting the solution too :)

PS. I'm going to move this across to the SQL Server forum as it's really where it belongs, but to be clear, the OP has already found and posted an answer.
Jun 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Susie Swint | last post by:
I have the following IIf statement which worked in Access 95 but will not work in Access 2002. The error message I get is that the expression is typed incorrectly, or is too complex to be...
3
by: NeilH | last post by:
Hello All I was wondering if someone could offer a rather inexperienced person some advice. Im trying to get my asp page to look at an access data I created the following query in access...
7
by: Aaron G via AccessMonster.com | last post by:
Wanted to share a solution to something which I didn't find on the net: EVERY form in my Microsoft Access 2002 database gave an error any time any code was to be called: form OnOpen, button...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
4
by: mukesh | last post by:
One another problem I have used a formula in the calculated field of a query as - IIf( <=, (IIf(<=, , ), (IIf (<=, , )) the above formula is working properly to give the lowest of , and ...
4
by: Takeadoe | last post by:
Dear NG - I've got a bunch of SQL statements (Insert Into "Access Table Name") generated from another software program. They look like this: Pasting these lines into the SQL view as they are...
4
by: ebasshead | last post by:
Hi Everybody, I want to be able to put a number in a txt box and if its between 5 and 9, for it to appear as a count in another txt box ie if the number inputed is 7 then 1 will appear in the second...
1
by: Chesne | last post by:
I am trying to return several value in and IF in a query statement. The generic is as follows... =IIf(!!=10,Between 1 and 10,"") Can anyone help with the "Between" part. I realise that it...
21
by: Mike N. | last post by:
Can someone tell me if there is a C# equivelent to the VBA 'with' statement that works like this: Set myControl = CommandBars(PopUpToUse).Controls.Add(msoControlButton, before:=5) With...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.