473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

At most one record can be returned by this subquery

1 New Member
Hi - I have spent all morning surfing this problem and cannot find a match that might help so am asking for help.
I want to fill a dataset with information about orders placed for a particular type of boat. This information comes from my Order_Tbl. In two of the columns I want to have information about lineitems for the particular order. This information is coming from the OrderLineitem_Tbl but to access the name of the sail I need to look in the QuoteSailType_Tbl as only the key is stored in the OrderLineitem_Tbl.
I have tried each individual subquery which works if I can give the actual OrderID, however when I try and place it all together using the OrderID from the first part of the query, I get the multiple sail types associated with the GenBoatID not the OrderID.
Can anyone help please.
Here is my SQL statement
SELECT O.WorksOrderNumber, O.ExtraOrderNo, left(O.OrderDateCreated, 10) as OrderDateCreated, O.DeliveryWeek, O.OrderID, O.OEMOrder, O.BoatGenID, (SELECT distinct (QuoteSailType_Tbl.SailType) as SailType FROM (Order_Tbl AS O INNER JOIN OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID WHERE (((OrderLineItem_Tbl.LineItem)=1) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as Lineitem1, (SELECT distinct (QuoteSailType_Tbl.SailType) as SailType FROM (Order_Tbl AS O INNER JOIN OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID WHERE (((OrderLineItem_Tbl.LineItem)=2) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as Lineitem2 FROM Order_Tbl O WHERE O.OEMOrder=True and O.BoatGenID=" & DDLBoatType.SelectedValue & " order by OrderID desc
Mar 10 '08 #1
1 2555
deepuv04
227 Recognized Expert New Member
Hi - I have spent all morning surfing this problem and cannot find a match that might help so am asking for help.
I want to fill a dataset with information about orders placed for a particular type of boat. This information comes from my Order_Tbl. In two of the columns I want to have information about lineitems for the particular order. This information is coming from the OrderLineitem_Tbl but to access the name of the sail I need to look in the QuoteSailType_Tbl as only the key is stored in the OrderLineitem_Tbl.
I have tried each individual subquery which works if I can give the actual OrderID, however when I try and place it all together using the OrderID from the first part of the query, I get the multiple sail types associated with the GenBoatID not the OrderID.
Can anyone help please.
Here is my SQL statement
SELECT O.WorksOrderNumber, O.ExtraOrderNo, left(O.OrderDateCreated, 10) as OrderDateCreated, O.DeliveryWeek, O.OrderID, O.OEMOrder, O.BoatGenID, (SELECT distinct (QuoteSailType_Tbl.SailType) as SailType FROM (Order_Tbl AS O INNER JOIN OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID WHERE (((OrderLineItem_Tbl.LineItem)=1) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as Lineitem1, (SELECT distinct (QuoteSailType_Tbl.SailType) as SailType FROM (Order_Tbl AS O INNER JOIN OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID WHERE (((OrderLineItem_Tbl.LineItem)=2) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as Lineitem2 FROM Order_Tbl O WHERE O.OEMOrder=True and O.BoatGenID=" & DDLBoatType.SelectedValue & " order by OrderID desc
Try the following query....
if you want to return at least one record use left outer join...

Expand|Select|Wrap|Line Numbers
  1. SELECT O.WorksOrderNumber, O.ExtraOrderNo, left(O.OrderDateCreated, 10) as OrderDateCreated, 
  2.     O.DeliveryWeek, O.OrderID, O.OEMOrder, O.BoatGenID,L1.SailType AS Lineitem1, L2.SailType AS Lineitem2
  3. FROM Order_Tbl O INNER JOIN
  4.      (   SELECT distinct O.OrderID,(QuoteSailType_Tbl.SailType) as SailType 
  5.         FROM (Order_Tbl AS O INNER JOIN 
  6.         OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN 
  7.         QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID 
  8.         WHERE (((OrderLineItem_Tbl.LineItem)=1) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as L1 
  9.              on  L1.OrderID = O.OrderID
  10.     (   SELECT distinct O.OrderID,(QuoteSailType_Tbl.SailType) as SailType 
  11.         FROM (Order_Tbl AS O INNER JOIN 
  12.         OrderLineItem_Tbl ON O.OrderID = OrderLineItem_Tbl.OrderID) INNER JOIN 
  13.         QuoteSailType_Tbl ON OrderLineItem_Tbl.QuoteSailTypeID = QuoteSailType_Tbl.QuoteSailTypeID 
  14.         WHERE (((OrderLineItem_Tbl.LineItem)=2) and ((O.OrderID)=OrderLineItem_Tbl.OrderID))) as L2
  15.               ON L2.OrderID = O.OrderID
  16. WHERE O.OEMOrder=True and O.BoatGenID=" & DDLBoatType.SelectedValue & " 
  17. order by OrderID desc
  18.  
  19.  
Mar 10 '08 #2

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

Similar topics

6
2960
by: Bob M | last post by:
Hi all, I am trying to update a record with a function value. Here is the function: update ITSM_SER_CUSTOM_FIELDS set SCF_SCDATE2 = SLA_PENDING_DATE.GET_DL(2292,'servicecall') where...
1
2287
by: philipdm | last post by:
Ok, I have a data warehouse that I am pulling records from using Oracle SQL. I have a select statement that looks like the one below. Now what I need to do is where the astrics are **** create a...
3
14111
by: John Ortt | last post by:
> I have a table of dates in ascending order but with varying intervals. I > would like to create a query to pull out the date (in field 1) and then pull > the date from the subsequent record...
5
6569
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
2
2468
by: Prabu Subroto | last post by:
Dear my friends... I created a table (named : sven1). I want to populate this table with the record from another table (named : appoinment). but I don't know how to formulate the sql query. ...
7
1741
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
3
2898
by: Shals | last post by:
Hi, I'm using Form and a subform control within that form. Main form is getting data from one table(Buildings) and subform is getting data from another table(BldgDataByFloor). but both the form...
3
25544
by: Chris | last post by:
Is it possiable to have a iif function in a query where it looks at the next record. for example if I run the query which lists years and if the results in record 2 equals the result in record 1...
0
1265
by: fubaba | last post by:
hi, i execute a store procedure got Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'...
0
7157
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,...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
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...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
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
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.