MDX query had executed so long - mdx

I have a MDX-query:
SELECT
{[Measures].[Count of Tickets], [Measures].[Ticket Average Per Day]} ON COLUMNS,
{[Specification].[Specification].Members} ON ROWS
FROM [Tickets Star Schema]
WHERE
({Filter([Creation Date].[Day].Members, [Creation Date].[Day].CurrentMember.Name >= '2017/02/06' AND [Creation Date].[Day].CurrentMember.Name <= '2017/02/13')} * ({[Ticket Type].[Ticket Type].[9145452713113549283], [Ticket Type].[Ticket Type].[9134488303913230171], [Ticket Type].[Ticket Type].[9138837241613081595], [Ticket Type].[Ticket Type].[9138836630013081453], [Ticket Type].[Ticket Type].[9134833380413407058], [Ticket Type].[Ticket Type].[9145452713113549281], [Ticket Type].[Ticket Type].[9134911151013454609], [Ticket Type].[Ticket Type].[9134783010613387189], [Ticket Type].[Ticket Type].[9134783010613387187], [Ticket Type].[Ticket Type].[9138837241613081613], [Ticket Type].[Ticket Type].[9134654662613285455], [Ticket Type].[Ticket Type].[9140432570013809078], [Ticket Type].[Ticket Type].[9145452972713549451], [Ticket Type].[Ticket Type].[9140432570013809076], [Ticket Type].[Ticket Type].[9138836630013081428], [Ticket Type].[Ticket Type].[9145452972713549453], [Ticket Type].[Ticket Type].[9145452972713549455], [Ticket Type].[Ticket Type].[9145452972713549457], [Ticket Type].[Ticket Type].[9145452972713549459], [Ticket Type].[Ticket Type].[9145609457713578112], [Ticket Type].[Ticket Type].[9134792932413392960], [Ticket Type].[Ticket Type].[9134833277313407014], [Ticket Type].[Ticket Type].[9134792932413392962], [Ticket Type].[Ticket Type].[9134911151013454617], [Ticket Type].[Ticket Type].[9134911151013454615], [Ticket Type].[Ticket Type].[9138836630013081446], [Ticket Type].[Ticket Type].[9145452713113549279], [Ticket Type].[Ticket Type].[9145452713113549277], [Ticket Type].[Ticket Type].[9138837241613081620], [Ticket Type].[Ticket Type].[9145452713113549275], [Ticket Type].[Ticket Type].[9139560292713345110], [Ticket Type].[Ticket Type].[9145609457713578108], [Ticket Type].[Ticket Type].[9134654662613285461], [Ticket Type].[Ticket Type].[9134654662613285463], [Ticket Type].[Ticket Type].[9139560292713345112], [Ticket Type].[Ticket Type].[9145609457713578106], [Ticket Type].[Ticket Type].[9134792932413392958], [Ticket Type].[Ticket Type].[9134488303913230179], [Ticket Type].[Ticket Type].[9135138327113743686], [Ticket Type].[Ticket Type].[9134783010613387181], [Ticket Type].[Ticket Type].[9134488303913230177]}))
And I have a aggregate table, which using by mondrian during to execute query. But this query is executing so long! When I less count of "Ticket Type" filters, query is executing more fast! Please explain why.

Crossjoins aren't memory cheap operations. Try to replace "*" with "," :
SELECT
{[Measures].[Count of Tickets], [Measures].[Ticket Average Per Day]} ON COLUMNS,
{[Specification].[Specification].Members} ON ROWS
FROM [Tickets Star Schema]
WHERE
({Filter([Creation Date].[Day].Members, [Creation Date].[Day].CurrentMember.Name >= '2017/02/06' AND [Creation Date].[Day].CurrentMember.Name <= '2017/02/13')}, ({[Ticket Type].[Ticket Type].[9145452713113549283], [Ticket Type].[Ticket Type].[9134488303913230171], [Ticket Type].[Ticket Type].[9138837241613081595], [Ticket Type].[Ticket Type].[9138836630013081453], [Ticket Type].[Ticket Type].[9134833380413407058], [Ticket Type].[Ticket Type].[9145452713113549281], [Ticket Type].[Ticket Type].[9134911151013454609], [Ticket Type].[Ticket Type].[9134783010613387189], [Ticket Type].[Ticket Type].[9134783010613387187], [Ticket Type].[Ticket Type].[9138837241613081613], [Ticket Type].[Ticket Type].[9134654662613285455], [Ticket Type].[Ticket Type].[9140432570013809078], [Ticket Type].[Ticket Type].[9145452972713549451], [Ticket Type].[Ticket Type].[9140432570013809076], [Ticket Type].[Ticket Type].[9138836630013081428], [Ticket Type].[Ticket Type].[9145452972713549453], [Ticket Type].[Ticket Type].[9145452972713549455], [Ticket Type].[Ticket Type].[9145452972713549457], [Ticket Type].[Ticket Type].[9145452972713549459], [Ticket Type].[Ticket Type].[9145609457713578112], [Ticket Type].[Ticket Type].[9134792932413392960], [Ticket Type].[Ticket Type].[9134833277313407014], [Ticket Type].[Ticket Type].[9134792932413392962], [Ticket Type].[Ticket Type].[9134911151013454617], [Ticket Type].[Ticket Type].[9134911151013454615], [Ticket Type].[Ticket Type].[9138836630013081446], [Ticket Type].[Ticket Type].[9145452713113549279], [Ticket Type].[Ticket Type].[9145452713113549277], [Ticket Type].[Ticket Type].[9138837241613081620], [Ticket Type].[Ticket Type].[9145452713113549275], [Ticket Type].[Ticket Type].[9139560292713345110], [Ticket Type].[Ticket Type].[9145609457713578108], [Ticket Type].[Ticket Type].[9134654662613285461], [Ticket Type].[Ticket Type].[9134654662613285463], [Ticket Type].[Ticket Type].[9139560292713345112], [Ticket Type].[Ticket Type].[9145609457713578106], [Ticket Type].[Ticket Type].[9134792932413392958], [Ticket Type].[Ticket Type].[9134488303913230179], [Ticket Type].[Ticket Type].[9135138327113743686], [Ticket Type].[Ticket Type].[9134783010613387181], [Ticket Type].[Ticket Type].[9134488303913230177]}))

Replace the Where clause with this one:
Filter is really heavy operation, you can easly do it with a Range(:)
WHERE
(
{
[Creation Date].[Day].[2017/02/06]:[Creation Date].[Day].[2017/02/13]
},
{
[Ticket Type].[Ticket Type].[9145452713113549283],
[Ticket Type].[Ticket Type].[9134488303913230171],
[Ticket Type].[Ticket Type].[9138837241613081595],
[Ticket Type].[Ticket Type].[9138836630013081453],
[Ticket Type].[Ticket Type].[9134833380413407058],
[Ticket Type].[Ticket Type].[9145452713113549281],
[Ticket Type].[Ticket Type].[9134911151013454609],
[Ticket Type].[Ticket Type].[9134783010613387189],
[Ticket Type].[Ticket Type].[9134783010613387187],
[Ticket Type].[Ticket Type].[9138837241613081613],
[Ticket Type].[Ticket Type].[9134654662613285455],
[Ticket Type].[Ticket Type].[9140432570013809078],
[Ticket Type].[Ticket Type].[9145452972713549451],
[Ticket Type].[Ticket Type].[9140432570013809076],
[Ticket Type].[Ticket Type].[9138836630013081428],
[Ticket Type].[Ticket Type].[9145452972713549453],
[Ticket Type].[Ticket Type].[9145452972713549455],
[Ticket Type].[Ticket Type].[9145452972713549457],
[Ticket Type].[Ticket Type].[9145452972713549459],
[Ticket Type].[Ticket Type].[9145609457713578112],
[Ticket Type].[Ticket Type].[9134792932413392960],
[Ticket Type].[Ticket Type].[9134833277313407014],
[Ticket Type].[Ticket Type].[9134792932413392962],
[Ticket Type].[Ticket Type].[9134911151013454617],
[Ticket Type].[Ticket Type].[9134911151013454615],
[Ticket Type].[Ticket Type].[9138836630013081446],
[Ticket Type].[Ticket Type].[9145452713113549279],
[Ticket Type].[Ticket Type].[9145452713113549277],
[Ticket Type].[Ticket Type].[9138837241613081620],
[Ticket Type].[Ticket Type].[9145452713113549275],
[Ticket Type].[Ticket Type].[9139560292713345110],
[Ticket Type].[Ticket Type].[9145609457713578108],
[Ticket Type].[Ticket Type].[9134654662613285461],
[Ticket Type].[Ticket Type].[9134654662613285463],
[Ticket Type].[Ticket Type].[9139560292713345112],
[Ticket Type].[Ticket Type].[9145609457713578106],
[Ticket Type].[Ticket Type].[9134792932413392958],
[Ticket Type].[Ticket Type].[9134488303913230179],
[Ticket Type].[Ticket Type].[9135138327113743686],
[Ticket Type].[Ticket Type].[9134783010613387181],
[Ticket Type].[Ticket Type].[9134488303913230177]
}
)

Related

SUMIF SQL MS Access

SELECT [doc type], [Open Amount],
[customer number],
COUNT([customer number]) As CountCustomerNumber,
SUM(IIF([Open Amount]>'0', [Open Amount], 0)) AS sum_open_amount_pos,
SUM(IIF([Open Amount]<'0', [Open Amount], 0)) As sum_open_amount_neg
FROM
(
SELECT d.[customer number] & d.[membership number] AS CustMemb,
d.[customer number],
agg.[Open Amount],
agg.[doc type],
SUM(agg.[TotalSubOpenAmount]) AS SumOpenAmount
FROM
(
SELECT [doc type],
[customer number],
SUM([Open Amount]) AS TotalSubOpenAmount
FROM data
WHERE [doc type] = 'RU'
GROUP BY [doc type], [customer number], [Open Amount]
) agg
INNER JOIN [data] d
ON d.[customer number] = agg.[customer number]
GROUP BY d.[customer number] & d.[membership number],
d.[customer number],
agg.[doc type],
agg.[Open Amount]
) AS sub
GROUP BY [doc type], [customer number]
HAVING COUNT([customer number]) = 1
I am getting a Parameter Input on MS Access - Open Amount.
How do I reference the open amount in the from query?

"The multi-part identifier could not be bound" for update statement from 'inner' set to 'update' set

Error
'The multi-part identifier "ar_update.Id" could not be bound.'
as line denoted in sql script.
I also tried other columns for the errant join to try to prompt different errors and gives same error results.
Why/How to qualify the 'inner' processing set back to the 'update' set?
update ar_update
set ar_update.[GLEntry_Amount] = ar_sum.[GLEntry_Amount_sum]
from [dbo].[ASL_Result_VGO] as ar_update
join (select ar.[Id] as [Id]
,ar.[Company Id] as [Company Id]
,ar.[Schedule Name] as [Schedule Name]
,ar.[Line No_] as [Line No_]
,ar.[Row No_] as [Row No_]
,ar.[Posting Date] as [Posting Date]
,ar.[Business Centre Code] as [Business Centre Code]
,ar.[Site Locations Code] as [Site Locations Code]
,GLEntry_Amount_sum =
(select sum(are.[GLEntry_Amount])
from [dbo].[ASL_Result_VGO] as are
where are.[Company Id] = ar.[Company Id] and
are.[Schedule Name] = ar.[Schedule Name] and
are.[Posting Date] = ar.[Posting Date] and
are.[Business Centre Code] = ar.[Business Centre Code] and
are.[Site Locations Code] = ar.[Site Locations Code] and
are.[Row No_] in ( select * from dbo.udf_range_expand_VGO(ar.[Totaling]) )
)
from [dbo].[ASL_Result_VGO] as ar
where ar.[Id] = ar_update.[Id] -- The multi-part identifier "ar_update.Id" could not be bound.
) ar_sum on ar_update.[Id] = ar_sum.[Id]
where ar_update.[Totaling Type] = 2 and -- formulas
len(trim(ar_update.[Totaling])) > 0 and
charindex('..', ar_update.[Totaling]) > 0 -- P ranges
this happened because on where ar.[Id] = ar_update.[Id] because ar_update.[Id] is not a value it is a multivalued type, it's like you were comparing a list with an integer, try this
update ar_update
set ar_update.[GLEntry_Amount] = ar_sum.[GLEntry_Amount_sum]
from [dbo].[ASL_Result_VGO] as ar_update
join (select ar.[Id] as [Id]
,ar.[Company Id] as [Company Id]
,ar.[Schedule Name] as [Schedule Name]
,ar.[Line No_] as [Line No_]
,ar.[Row No_] as [Row No_]
,ar.[Posting Date] as [Posting Date]
,ar.[Business Centre Code] as [Business Centre Code]
,ar.[Site Locations Code] as [Site Locations Code]
,GLEntry_Amount_sum = (select sum(are.[GLEntry_Amount])
from [dbo].[ASL_Result_VGO] as are
where are.[Company Id] = ar.[Company Id] and
are.[Schedule Name] = ar.[Schedule Name] and
are.[Posting Date] = ar.[Posting Date] and
are.[Business Centre Code] = ar.[Business Centre Code] and
are.[Site Locations Code] = ar.[Site Locations Code] and
are.[Row No_] in ( select * from dbo.udf_range_expand_VGO(ar.[Totaling]) )
)
from [dbo].[ASL_Result_VGO] as ar
) ar_sum on ar_update.[Id] = ar_sum.[Id]
where ar_update.[Totaling Type] = 2 and -- formulas
len(trim(ar_update.[Totaling])) > 0 and
charindex('..', ar_update.[Totaling]) > 0

Filtering by an ISNULL statement within SELECT statement

I'm stuck on a portion of code where I can not figure out how to use ISNULL correctly.
I'm trying to find all sales prices for an item by location and by variant code. The issue is that not all items with variants are priced in the sales price table at the variant level. I'm trying to say if there is no variant match, find where variant = ''.
SELECT [Item Ledger].[Location Code], [Item Ledger].[Item No_] AS "No_", [Item Ledger].[Variant Code]
, (SELECT [Item].[Description] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Description"
, (SELECT [Item Variant].[Variant Dimension 1] FROM [Wings$Item Variant Registration] AS "Item Variant" WHERE [Item Variant].[Item No_] = [Item Ledger].[Item No_]
AND [Item Variant].[Variant] = [Item Ledger].[Variant Code]) AS "Color"
, (SELECT [Item Variant].[Variant Dimension 2] FROM [Wings$Item Variant Registration] AS "Item Variant" WHERE [Item Variant].[Item No_] = [Item Ledger].[Item No_]
AND [Item Variant].[Variant] = [Item Ledger].[Variant Code]) AS "Size"
, (SELECT [Item].[Vendor No_] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Vendor No."
, (SELECT [Item].[Division Code] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Division Code"
, (SELECT [Item].[Item Category Code] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Item Category Code"
, (SELECT [Item Category].[Description] FROM [Wings$Item Category] AS "Item Category" WHERE [Item Category].[Code] = [Item Ledger].[Item Category Code]) AS "Item Cat. Description"
, (SELECT [Item].[Product Group Code] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Product Group Code"
, (SELECT [Product Group].[Description] FROM [Wings$Product Group] AS "Product Group" WHERE [Product Group].[Code] = [Item Ledger].[Product Group Code]) AS "Prod. Group Description"
, (SELECT CAST([Item].[Last Direct Cost] AS decimal(18,2)) FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Item Ledger].[Item No_]) AS "Last Cost"
, (SELECT DISTINCT CAST(MAX([Sales Price].[Unit Price]) as decimal(18,2))
FROM [Wings$Sales Price] AS "Sales Price", [Wings$Store Price Group] AS "Store Price"
WHERE EXISTS
(SELECT DISTINCT [Store Price].[Store]
, [Sales Price].[Item No_]
, (SELECT [Item].[Description] FROM [Wings$Item] AS "Item" WHERE [Item].[No_] = [Sales Price].[Item No_]) AS "Description"
, [Sales Price].[Variant Code]
, [Sales Price].[Sales Code]
, CAST([Sales Price].[Unit Price] as decimal(18,2)) AS "Unit Price"
FROM [Wings$Sales Price] AS "Sales Price" JOIN [Wings$Picking _ Receiving lines] AS "Picking Lines" ON [Sales Price].[Item No_] = [Picking Lines].[Item No_]
JOIN [Wings$Store Price Group] AS "Store Price" ON [Store Price].[Price Group Code] = [Sales Price].[Sales Code]
AND [Store Price].[Store] = [Picking Lines].[Shortcut Dimension 1 Code] WHERE [Sales Price].[Starting Date] > [Sales Price].[Ending Date])
AND [Store Price].[Store] = [Item Ledger].[Location Code] AND [Sales Price].[Item No_] = [Item Ledger].[Item No_]
AND [Sales Price].[Variant Code] = [Item Ledger].[Variant Code] AND [Store Price].[Price Group Code] = [Sales Price].[Sales Code]) AS "Retail Price"
, (SELECT MIN([Purch Rec].[Posting Date]) FROM [Wings$Purch_ Rcpt_ Line] AS "Purch Rec" WHERE [Purch Rec].[No_] = [Item Ledger].[Item No_] AND [Purch Rec].[Variant Code] = [Item Ledger].[Variant Code])
AS "First Rec Date"
, (SELECT MAX([Purch Rec].[Posting Date]) FROM [Wings$Purch_ Rcpt_ Line] AS "Purch Rec" WHERE [Purch Rec].[No_] = [Item Ledger].[Item No_] AND [Purch Rec].[Variant Code] = [Item Ledger].[Variant Code])
AS "Last Rec Date"
, (SELECT MAX([Sales Line].[Date]) FROM [Wings$Trans_ Sales Entry] AS "Sales Line" WHERE [Sales Line].[Item No_] = [Item Ledger].[Item No_] AND [Sales Line].[Variant Code] = [Item Ledger].[Variant Code]
AND [Sales Line].[Store No_] = [Item Ledger].[Location Code]) AS "Last Sold Date"
, (SELECT CAST(SUM([Value Entry].[Item Ledger Entry Quantity]) AS decimal(18,0)) FROM [Wings$Value Entry] AS "Value Entry" WHERE [Value Entry].[Item No_] = [Item Ledger].[Item No_]
AND [Value Entry].[Variant Code] = [Item Ledger].[Variant Code] AND [Value Entry].[Location Code] = [Item Ledger].[Location Code] AND [Value Entry].[Posting Date] <= '20161201') AS "Beg. Balance"
, (SELECT CAST(SUM([Transfer Shipment].[Quantity]) AS decimal(18,0)) FROM [Wings$Transfer Shipment Line] AS "Transfer Shipment" WHERE [Transfer Shipment].[Item No_] = [Item Ledger].[Item No_]
AND [Transfer Shipment].[Variant Code] = [Item Ledger].[Variant Code] AND [Transfer Shipment].[Transfer-from Code] = [Item Ledger].[Location Code]) AS "Outbound Transfers"
, (SELECT CAST(SUM([Transfer Receipt].[Quantity]) AS decimal(18,0)) FROM [Wings$Transfer Receipt Line] AS "Transfer Receipt" WHERE [Transfer Receipt].[Item No_] = [Item Ledger].[Item No_]
AND [Transfer Receipt].[Variant Code] = [Item Ledger].[Variant Code] AND [Transfer Receipt].[Transfer-to Code] = [Item Ledger].[Location Code]) AS "Inbound Transfers"
, (SELECT CAST(SUM([Purch. Rec.].[Quantity]) AS decimal(18,0)) FROM [Wings$Purch_ Rcpt_ Line] AS "Purch. Rec." WHERE [Purch. Rec.].[No_] = [Item Ledger].[Item No_]
AND [Purch. Rec.].[Variant Code] = [Item Ledger].[Variant Code] AND [Purch. Rec.].[Location Code] = [Item Ledger].[Location Code]) AS "YTD Purchase Receipts"
, (SELECT CAST(SUM([Transaction Register].[Quantity]) as decimal(18,0)) FROM [Wings$Trans_ Sales Entry] AS "Transaction Register"
WHERE [Item Ledger].[Item No_] = [Transaction Register].[Item No_] AND [Item Ledger].[Variant Code] = [Transaction Register].[Variant Code]
AND [Item Ledger].[Location Code] = [Transaction Register].[Store No_]) AS "YTD Sales"
, (SELECT CAST(SUM([Transaction Register].[Quantity]) as decimal(18,0)) FROM [Wings$Trans_ Sales Entry] AS "Transaction Register"
WHERE [Item Ledger].[Item No_] = [Transaction Register].[Item No_] AND [Item Ledger].[Variant Code] = [Transaction Register].[Variant Code]
AND [Item Ledger].[Location Code] = [Transaction Register].[Store No_] AND [Transaction Register].[Date] >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) -1, 0)
AND [Transaction Register].[Date] < DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) , 0)) AS "Last Month Sales"
, (SELECT CAST(SUM([Transaction Register].[Quantity]) as decimal(18,0)) FROM [Wings$Trans_ Sales Entry] AS "Transaction Register"
WHERE [Item Ledger].[Item No_] = [Transaction Register].[Item No_] AND [Item Ledger].[Variant Code] = [Transaction Register].[Variant Code]
AND [Item Ledger].[Location Code] = [Transaction Register].[Store No_] AND [Transaction Register].[Date] >= DATEADD(DAY, 1-DAY(GETDATE()), GETDATE())
AND [Transaction Register].[Date] < EOMONTH(GETDATE())) AS "Current Month Sales"
, (SELECT CAST(SUM([Transfer Line].[Outstanding Quantity]) AS decimal(18,0)) FROM [Wings$Transfer Line] AS "Transfer Line" WHERE [Transfer Line].[Item No_] = [Item Ledger].[Item No_]
AND [Transfer Line].[Variant Code] = [Item Ledger].[Variant Code] AND [Transfer Line].[Transfer-to Code] = [Item Ledger].[Location Code]) AS "Current In-Transit to Store"
, (SELECT CAST(SUM([Item Ledger].[Quantity]) as decimal(18,0))) AS "Current on Hand"
, (SELECT CAST(SUM([Value Entry].[Item Ledger Entry Quantity]) as decimal(18,0)) FROM [Wings$Value Entry] AS "Value Entry" WHERE [Value Entry].[Item No_] = [Item Ledger].[Item No_]
AND [Value Entry].[Variant Code] = [Item Ledger].[Variant Code] AND [Value Entry].[Location Code] = [Item Ledger].[Location Code] AND [Value Entry].[Location Code] LIKE '9%') AS "Whse Inv."
, (SELECT CAST(SUM([Value Entry].[Item Ledger Entry Quantity]) as decimal(18,0)) FROM [Wings$Value Entry] AS "Value Entry" WHERE [Value Entry].[Item No_] = [Item Ledger].[Item No_]
AND [Value Entry].[Variant Code] = [Item Ledger].[Variant Code] AND [Value Entry].[Location Code] = [Item Ledger].[Location Code] AND [Value Entry].[Location Code] NOT LIKE '9%') AS "Store Inv."
, (SELECT CAST(SUM([Purchase Line].[Outstanding Quantity]) as decimal(18,0)) FROM [Wings$Purchase Line] AS "Purchase Line" WHERE [Item Ledger].[Item No_] = [Purchase Line].[No_]
AND [Purchase Line].[Location Code] = [Item Ledger].[Location Code] AND [Purchase Line].[Variant Code] = [Item Ledger].[Variant Code]) AS "Qty. on PO"
FROM [Wings$Item Ledger Entry] AS "Item Ledger", [Wings$Store Price Group] AS "Store Price" WHERE [Item Ledger].[Location Code] = [Store Price].[Store] AND [Item Ledger].[Location Code] = [Store Price].[Store]
GROUP BY [Item Ledger].[Location Code], [Item Ledger].[Item No_], [Item Ledger].[Variant Code], [Item Ledger].[Item Category Code], [Item Ledger].[Product Group Code], [Store Price].[Price Group Code], [Store Price].[Store]

Combobox on DataGridView

I have a combobox on a datagridview. I am able to populate the values of the combobox, but what I am failing to do is to populate the data base value into the combobox "text" when the datagridview is loading.
I hope this makes sense. Basically I just want the data returned to reflect in the combobox Display.
Your assistance will be highly appreciated.
Dim cbo As DataGridViewComboBoxColumn
If GlobalVariables.UsrSite = 0 Then
SQL.ReadQuery("Select LogsReason as [Logs Update], IncNo as [Number], SiteName As [Site Name], FleetNo As [Fleet No], FleetType As [Fleet Type], Location,
SMR as [Hours], TimeDown As [Down Time], EstTimeUp as [Est Repair], DateDiff(d, TimeDown, GetDate()) as [Days Down]
from UDOData where status = 'Down' order by [Days Down] Desc")
Else
SQL.ReadQuery("Select LogsReason as [Logs Update], IncNo as [Number], SiteName As [Site Name], FleetNo As [Fleet No], FleetType As [Fleet Type], Location,
SMR as [Hours], TimeDown As [Down Time], EstTimeUp as [Est Repair], DateDiff(d, TimeDown, GetDate()) as [Days Down] from UDOData
Where SiteID = " & GlobalVariables.UsrSite & " and Status = 'Down' order by [Days Down] Desc")
End If
dgvUDO.DataSource = SQL.SQLDS.Tables(0)
cbo.DataSource = SQL.SQLDS.Tables(0)
cbo.DisplayMember = "Logs Update"
cbo.ValueMember = "Logs Update"
cbo.DataPropertyName = "Logs Update"
I get exception error saying "logs Update" does not exist, but it loads in the datagridview.
I ended up doing this, which worked for me.
Dim cbo As DataGridViewComboBoxColumn
cbo = dgvUDO.Columns("cboLogsUDO")
Dim AltDb As New DataTable
SQL.ReadQuery("Select Descrip from dbo.UDOLogs")
AltDb = SQL.SQLDS.Tables(0)
'LOAD DATA GRID VIEW DATA
If GlobalVariables.UsrSite = 0 Then
SQL.ReadQuery("Select ID, LogsReason as [Logs Update], IncNo as [Number], SiteName As [Site Name], FleetNo As [Fleet No], FleetType As [Fleet Type], Location,
SMR as [Hours], TimeDown As [Down Time], EstTimeUp as [Est Repair], DateDiff(d, TimeDown, GetDate()) as [Days Down]
from UDOData where status = 'Down' order by [Days Down] Desc")
Else
SQL.ReadQuery("Select ID, LogsReason as [Logs Update], IncNo as [Number], SiteName As [Site Name], FleetNo As [Fleet No], FleetType As [Fleet Type], Location,
SMR as [Hours], TimeDown As [Down Time], EstTimeUp as [Est Repair], DateDiff(d, TimeDown, GetDate()) as [Days Down] from UDOData
Where SiteID = " & GlobalVariables.UsrSite & " and Status = 'Down' order by [Days Down] Desc")
End If
'SET DATA GRIDVIEW DATA SOURCE
dt = SQL.SQLDS.Tables(0)
dgvUDO.DataSource = dt
dgvUDO.Rows(0).Selected = True
'LOAD UPDATE COMMAND FOR DATA GRIDVIEW CHANGES
SQL.SQLDA.UpdateCommand = New SqlClient.SqlCommandBuilder(SQL.SQLDA).GetUpdateCommand
'HIDE UNWANTED COLUMNS
dgvUDO.Columns("Logs Update").Visible = False
dgvUDO.Columns("ID").Visible = False
'SET COMBOBOX ATTRIBUTES
cbo.DataSource = AltDb
cbo.DisplayMember = "Descrip"
cbo.ValueMember = "Descrip"
cbo.DataPropertyName = "Logs Update"
This gives me the ability to call the value in the returned db for the datagridview as the combobox "text" value, but show the drop down items as the items in another table.

Select Distinct Sum - GROUP BY

SELECT DISTINCT [SC Vermorel SRL$Production Order].No_,
[SC Vermorel SRL$Production Order].[Replan Ref_ No_],
[SC Vermorel SRL$Production Order].Description,
[SC Vermorel SRL$Production Order].[Source No_],
[SC Vermorel SRL$Production Order].[Routing No_],
[SC Vermorel SRL$Production Order].Quantity,
[SC Vermorel SRL$Production Order].[Old Prod_ Order No_],
[SC Vermorel SRL$Routing Line].[Run Time],
[SC Vermorel SRL$Routing Line].[Run Time] * [SC Vermorel SRL$Production Order].Quantity AS TotalOre,
[SC Vermorel SRL$Prod_ Order Line].[Finished Quantity],
SUM([SC Vermorel SRL$ProductieZilnica].[Cantitate sudura]) AS [Cantitate sudura],
SUM([SC Vermorel SRL$ProductieZilnica].[Cantitate montaj]) AS [Cantitate montaj]
FROM [SC Vermorel SRL$Production Order]
INNER JOIN [SC Vermorel SRL$Routing Line]
ON [SC Vermorel SRL$Production Order].[Routing No_] = [SC Vermorel SRL$Routing Line].[Routing No_]
INNER JOIN [SC Vermorel SRL$Prod_ Order Line]
ON [SC Vermorel SRL$Production Order].No_ = [SC Vermorel SRL$Prod_ Order Line].[Prod_ Order No_]
INNER JOIN [SC Vermorel SRL$ProductieZilnica]
ON [SC Vermorel SRL$Production Order].No_ = [SC Vermorel SRL$ProductieZilnica].RPO
WHERE ([SC Vermorel SRL$Production Order].Status = 3)
AND ([SC Vermorel SRL$Production Order].[Location Code] = 'MACH FIN')
AND ([SC Vermorel SRL$Production Order].[Gen_ Prod_ Posting Group] = 'FINISHED G')
AND ([SC Vermorel SRL$Routing Line].No_ = '150')
GROUP BY [SC Vermorel SRL$Production Order].No_
I need to attach the sum of all the entries from another table ([SC Vermorel SRL$ProductieZilnica]) which corresponds to each distinct No_ from [SC Vermorel SRL$Production Order] table.
I cant for the love of God make it work. Can someone point me in the right direction?
At first, use table aliases - it will make your query more readable.
If you are using GROUP BY you need to add all columns, except one that are in aggregation function (you got SUM) like:
SELECT PO.No_,
PO.[Replan Ref_ No_],
PO.[Description],
PO.[Source No_],
PO.[Routing No_],
PO.Quantity,
PO.[Old Prod_ Order No_],
RL.[Run Time],
RL.[Run Time] * PO.Quantity AS TotalOre,
POL.[Finished Quantity],
SUM(PZ.[Cantitate sudura]) AS [Cantitate sudura],
SUM(PZ.[Cantitate montaj]) AS [Cantitate montaj]
FROM [SC Vermorel SRL$Production Order] PO
INNER JOIN [SC Vermorel SRL$Routing Line] RL
ON PO.[Routing No_] = RL.[Routing No_]
INNER JOIN [SC Vermorel SRL$Prod_ Order Line] POL
ON PO.No_ = POL.[Prod_ Order No_]
INNER JOIN [SC Vermorel SRL$ProductieZilnica] PZ
ON PO.No_ = PZ.RPO
WHERE (PO.Status = 3) AND (PO.[Location Code] = 'MACH FIN') AND
(PO.[Gen_ Prod_ Posting Group] = 'FINISHED G') AND (RL.No_ = '150')
GROUP BY PO.No_,
PO.[Replan Ref_ No_],
PO.[Description],
PO.[Source No_],
PO.[Routing No_],
PO.Quantity,
PO.[Old Prod_ Order No_],
RL.[Run Time],
PO.Quantity,
POL.[Finished Quantity]