Wednesday, 19 October 2011

FilterText property example on a Sage 200 business object

This example show how to use the filter text property on a sage 200 business object.

Private Function GetPOPQtyBreakCostPrice(oStockItem As Sage.Accounting.Stock.StockItem, quantity As Decimal) As Decimal

Dim oSupplier = CType(Me._AmendableForm.BoundObjects(0), Sage.Accounting.POP.POPOrderReturnLine).POPOrderReturn.Supplier

Using oPOPQTYBreakPrices As New SCITSupplierStockQtyBreaks

oPOPQTYBreakPrices.Query.Filters.Add(New Sage.ObjectStore.Filter(SCITSupplierStockQtyBreak.FIELD_STOCKITEMDBKEY, CInt(oStockItem.PrimaryKey.Value)))

oPOPQTYBreakPrices.Query.Filters.Add(New Sage.ObjectStore.Filter(SCITSupplierStockQtyBreak.FIELD_SUPPLIERDBKEY, CInt(oSupplier.PrimaryKey.Value)))

'Dim oFilterFromQty As New Sage.ObjectStore.Filter(quantity, Sage.Common.Data.FilterOperator.GreaterThanOrEqual, SCITSupplierStockQtyBreak.FIELD_FROMQUANTITY)

'oFilterFromQty.BoundParameter = False

'oPOPQTYBreakPrices.Query.Filters.Add(oFilterFromQty)

'Dim oFilterToQty As New Sage.ObjectStore.Filter(quantity, Sage.Common.Data.FilterOperator.GreaterThanOrEqual, SCITSupplierStockQtyBreak.FIELD_TOQUANTITY)

'oFilterFromQty.BoundParameter = False

'oPOPQTYBreakPrices.Query.Filters.Add(oFilterToQty)

Try

oPOPQTYBreakPrices.Query.FilterText = String.Format("{0} >= FromQuantity and {0} <= ToQuantity", quantity)

' Dim oCmd = oPOPQTYBreakPrices.

oPOPQTYBreakPrices.Find()

If oPOPQTYBreakPrices.First Is Nothing Then

Return 0D

Else

Return oPOPQTYBreakPrices.First.CostPrice

End If

Catch ex As Exception

Return 0

End Try



End Using

End Function

InFilter example when using Sage 200 object store builder

This example show how to use the infilter object on a sage 200 business object.

IfDisplayUnassignedUnitsOnly Then

Dim oListUnitPK As New List(Of Object)

Using oTenancyies As New SCIT.DHT.Accounting.SCITTenancies

For Each oTenancy As SCIT.DHT.Accounting.SCITTenancy In oTenancyies

oListUnitPK.Add(CInt(oTenancy.Unit.PrimaryKey.Value))

Next

End Using

Dim NotInFilter As Sage.ObjectStore.InFilter

NotInFilter = Sage.ObjectStore.InFilter.CreateNew(SCIT.DHT.Accounting.SCITUnit.FIELD_SCITUNIT, Sage.Common.Expressions.InOperator.NotIn, oListUnitPK.ToArray)

Units.Query.Filters.Add(NotInFilter)

End If

If Units.Query.Filters.Count > 0 Then

Units.Find()

End If

Thursday, 6 October 2011

Check Index Fragmentation on SQL server


USE CRM

GO

SELECT
a.index_id, name, avg_fragmentation_in_percent

FROM sys.dm_db_index_physical_stats (DB_ID(), NULL,

NULL, NULL, NULL) AS a

JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;

GO