473,320 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SQL nightmare

I am trying to convert an application writtten in Access to vb.net. Alot of the SQL statements are long. Can someone take a look at the following Access SQL statemnt and tell me what SQL statement would look like? This statement works in Access, but the INSERT INTO and FROM tables are the same???
BTW,, A load number looks like this "########-A" or "########-B" etc.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Statements ( MachineID, ShipDate, InvoicedDate, OutgoingLoadNum, ShipAdd1, ShipAdd2, ShipCity, ShipState, ShipZip, ShipZipPlus4, BillAdd1, BillAdd2, BillCity, BillState, BillZip, BillZipPlus4, CustomerName, IsStatement )
  2. SELECT DISTINCT 
  3. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="A",DMin('MachineID','Statements')-1,
  4. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="B",DMin("[MachineID]","[Statements]")-2,
  5. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="C",DMin("[MachineID]","[Statements]")-3,
  6. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="D",DMin("[MachineID]","[Statements]")-4,
  7. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="E",DMin("[MachineID]","[Statements]")-5,
  8. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="F",DMin("[MachineID]","[Statements]")-6,
  9. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="G",DMin("[MachineID]","[Statements]")-7,
  10. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="H",DMin("[MachineID]","[Statements]")-8,
  11. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="I",DMin("[MachineID]","[Statements]")-9))))))))) 
  12. AS MachID, Statements.ShipDate, Statements.InvoicedDate, Statements.OutgoingLoadNum, Statements.ShipAdd1, Statements.ShipAdd2, Statements.ShipCity, Statements.ShipState, Statements.ShipZip, Statements.ShipZipPlus4, Statements.BillAdd1, Statements.BillAdd2, Statements.BillCity, Statements.BillState, Statements.BillZip, Statements.BillZipPlus4, Statements.CustomerName, -1 AS IsStatemnt
  13. FROM Statements;
Jul 19 '07 #1
1 1260
nico5038
3,080 Expert 2GB
I am trying to convert an application writtten in Access to vb.net. Alot of the SQL statements are long. Can someone take a look at the following Access SQL statemnt and tell me what SQL statement would look like? This statement works in Access, but the INSERT INTO and FROM tables are the same???
BTW,, A load number looks like this "########-A" or "########-B" etc.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Statements ( MachineID, ShipDate, InvoicedDate, OutgoingLoadNum, ShipAdd1, ShipAdd2, ShipCity, ShipState, ShipZip, ShipZipPlus4, BillAdd1, BillAdd2, BillCity, BillState, BillZip, BillZipPlus4, CustomerName, IsStatement )
  2. SELECT DISTINCT 
  3. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="A",DMin('MachineID','Statements')-1,
  4. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="B",DMin("[MachineID]","[Statements]")-2,
  5. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="C",DMin("[MachineID]","[Statements]")-3,
  6. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="D",DMin("[MachineID]","[Statements]")-4,
  7. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="E",DMin("[MachineID]","[Statements]")-5,
  8. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="F",DMin("[MachineID]","[Statements]")-6,
  9. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="G",DMin("[MachineID]","[Statements]")-7,
  10. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="H",DMin("[MachineID]","[Statements]")-8,
  11. IIf(Mid([OutgoingLoadNum],InStr(1,[OutgoingLoadNum],"-")+1)="I",DMin("[MachineID]","[Statements]")-9))))))))) 
  12. AS MachID, Statements.ShipDate, Statements.InvoicedDate, Statements.OutgoingLoadNum, Statements.ShipAdd1, Statements.ShipAdd2, Statements.ShipCity, Statements.ShipState, Statements.ShipZip, Statements.ShipZipPlus4, Statements.BillAdd1, Statements.BillAdd2, Statements.BillCity, Statements.BillState, Statements.BillZip, Statements.BillZipPlus4, Statements.CustomerName, -1 AS IsStatemnt
  13. FROM Statements;
This nested IIF statements are checking for the character after the first "-" sign.
When "A" the minimum MachineID from the table Statements is corrected with -1, when "B" with -2, etc.

It would have been shorter to use the corretce ascii value of these characters :-)

Nic;o)
Aug 1 '07 #2

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

Similar topics

1
by: Drisco | last post by:
Hello, I realy need help,Searched the NG for a days with no vail. Sorry for the long script. I am trying to get a variable from php to flash. I have the following code in php <a...
0
by: Deena | last post by:
Hi Windows forms layout is turning to be a nightmare. I add my controls to a form and then save it and then it just get's all messed up. I'm using inheritance if this makes any difference. Also...
4
by: Dave | last post by:
Hello All, I am having a nightmare trying to add a new row to my Datagrid. When I use the code below I get the error: 'Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount. Can...
6
by: Jim Mirra | last post by:
Hey, I have been working on this for a while now and I keep getting the same error. here is my code: ------- start code --------- Dim strSQL = "Select tagid,itemid,description,status,...
2
by: Afshar | last post by:
Dear nice people around the world! Please help ending this nightmare, I have 2 problem with ASP.NET Menu control First: I have a horizontal menu at top of my page, each item have some sub-items...
3
by: Samuel Shulman | last post by:
I get the following error Error 2 Could not load file or assembly 'RusticiSoftware.ScormContentPlayer.Logic, Version=2006.1.2576.40320, Culture=neutral,...
10
by: Andrew Wan | last post by:
I have been having a nightmare with ASP/ASP.NET & IIS6. We use Msxml2.DOMDocument.4.0 object to create a XML object in ASP. The Msxml2.DOMDocument.4.0 is from the Windows Platform SDK Feb 2003...
1
by: =?Utf-8?B?TWVyZGFhZA==?= | last post by:
I am using ASP.NET 2.0 C# I am getting errors when I publish my site. It works fine on our local server. Pages that have maintainscrollpositiononpostback=true set, get errors such as:...
2
by: Phillip Taylor | last post by:
I'm having an absolute nightmare with regular diff tools which is making it really hard to manage changes etc in CVS. Tools such as WinMerge and ViewCVS really have really poor matching results...
6
by: Widge | last post by:
I'm having a nightmare. I've used this technique before and can't understand why I'm getting an error using it now. Basically I have a form, on that is a sub form datasheet. What I am eventually...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.