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
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... -
SELECT O.WorksOrderNumber, O.ExtraOrderNo, left(O.OrderDateCreated, 10) as OrderDateCreated,
-
O.DeliveryWeek, O.OrderID, O.OEMOrder, O.BoatGenID,L1.SailType AS Lineitem1, L2.SailType AS Lineitem2
-
FROM Order_Tbl O INNER JOIN
-
( SELECT distinct O.OrderID,(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 L1
-
on L1.OrderID = O.OrderID
-
( SELECT distinct O.OrderID,(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 L2
-
ON L2.OrderID = O.OrderID
-
WHERE O.OEMOrder=True and O.BoatGenID=" & DDLBoatType.SelectedValue & "
-
order by OrderID desc
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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.
...
| |
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...
|
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...
|
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...
|
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.'...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |