24. September 2012 16:13
24. September 2012 17:47
exec sp_databases USE Databasename
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES25. September 2012 08:18
SELECT [name] FROM sys.objects
WHERE [type] = 'U'
25. September 2012 08:32
   Function GetNAVTableObjects() As DataTable
        Dim myConnection As New SqlConnection
        If My.Application.SQLAuth = "Database" Then
            myConnection.ConnectionString = "server=" & My.Application.SQLServer & ";Trusted_Connection=False;database=" & My.Application.SQLDatabase & "User ID=" & My.Application.SQLUser & ";Password=" & My.Application.SQLUserPassword & ";"
        Else '"Windows"
            myConnection.ConnectionString = "server=" & My.Application.SQLServer & ";Trusted_Connection=true;database=" & My.Application.SQLDatabase & ";"
        End If
        Dim myCommand As New SqlCommand
        myCommand.CommandText = "SELECT [timestamp],[Type],[Company Name] as CompanyName,[ID],[Name],[Modified],[Compiled],[BLOB Reference] as BLOBReference,[BLOB Size] as BLOBSize,[DBM Table No_] as DBMTableNo,[Date],[Time],[Version List] as VersionList,[Locked],[Locked By] as LockedBy FROM [Object] where [Type]=0"
        myCommand.Connection = myConnection
        Dim da As New SqlDataAdapter
        da.SelectCommand = myCommand
        Dim ds As New DataSet
        myConnection.Open()
        da.Fill(ds, "object")
        myConnection.Close()
        Return ds.Tables("object")
    End Function
    Function GetNAVTableName(NAVTableID As String) As String
        Dim tablename As String = ""
        Dim foundrows() As DataRow
        foundrows = GetNAVTableObjects.Select("ID=" & NAVTableID)
        If foundrows.Count = 0 Then
            MsgBox("Tabelle " & NAVTableID & " nicht vorhanden")
            Exit Function
        End If
        For Each row As DataRow In foundrows
            If row("CompanyName").ToString.Length > 0 Then
                If My.Application.NAVCompany = row("CompanyName") Then
                    'Tabelle: Datapercompany=yes => tabellenname=Mandant$tabname
                    tablename = row("CompanyName") & "$" & row("Name")
                    Exit For
                End If
            Else
                tablename = row("Name")
                Exit For
            End If
        Next
        Return tablename
    End Function                Dim myConnection As New SqlConnection
                If My.Application.SQLAuth = "Database" Then
                    myConnection.ConnectionString = "server=" & My.Application.SQLServer & ";Trusted_Connection=False;database=" & My.Application.SQLDatabase & "User ID=" & My.Application.SQLUser & ";Password=" & My.Application.SQLUserPassword & ";"
                Else '"Windows"
                    myConnection.ConnectionString = "server=" & My.Application.SQLServer & ";Trusted_Connection=true;database=" & My.Application.SQLDatabase & ";"
                End If
                Dim myCommand As New SqlCommand
                Dim itemtablename, bomtablename, ledgertablename As String
                itemtablename = GetNAVTableName("27")
                bomtablename = GetNAVTableName("90")
                ledgertablename = GetNAVTableName("32") & "$VSIFT$3"
                myCommand.CommandText = "SELECT TOP (100) PERCENT a.No_ AS No, a.Description, a.[Search Description] AS Matchcode, " & _
                "a.[Item Category Code] AS ItemCategory, a.[Product Group Code] AS ProductGroup, " & _
                "a.[Base Unit of Measure] AS BaseUnitOfMeasure, CASE WHEN b.[No_] IS NULL THEN 0 ELSE 1 END AS BillOfMaterials, SUM(c.SUM$Quantity) AS Inventory, a.Blocked, " & _
                "a.[Unit Cost] AS UnitCost, a.[Unit Price] AS UnitPrice, a.[Gen_ Prod_ Posting Group] AS ProductPostingGroup, a.[VAT Prod_ Posting Group] AS VATPostingGroup, " & _
                "a.[Price Includes VAT] AS PriceIncludingTax, a.[Costing Method] AS CostingMethod, a.[Inventory Posting Group] AS InventoryPostingGroup, a.[Last Direct Cost] AS LastDirectCost, " & _
                "a.[Vendor No_] AS VendorNo, a.[Vendor Item No_] AS VendorItemNo, a.[Purch_ Unit of Measure] AS PurchaseUnitOfMeasure, a.[Lead Time Calculation] AS LeadTime, " & _
                "a.[Tariff No_] AS TariffNo, a.[Country_Region of Origin Code] AS CountryOfOrigin, a.[Net Weight] AS NetWeight, a.[Gross Weight] AS GrossWeight " & _
                "FROM [" & itemtablename & "] as a LEFT OUTER JOIN [" & bomtablename & "] as b ON a.No_ = b.[Parent Item No_] LEFT OUTER JOIN [" & ledgertablename & "] as c ON a.No_ = c.[Item No_] " & _
                "GROUP BY a.No_, a.Description, a.[Search Description], a.[Item Category Code], a.[Product Group Code], a.[Base Unit of Measure], a.Blocked, a.[Unit Cost], " & _
                      "a.[Unit Price], a.[Gen_ Prod_ Posting Group], a.[VAT Prod_ Posting Group], a.[Price Includes VAT], a.[Costing Method], a.[Inventory Posting Group], " & _
                      "a.[Last Direct Cost], a.[Vendor No_], a.[Vendor Item No_], a.[Purch_ Unit of Measure], a.[Lead Time Calculation], a.[Tariff No_], " & _
                      "a.[Country_Region of Origin Code], a.[Net Weight], a.[Gross Weight], CASE WHEN b.[No_] IS NULL THEN 0 ELSE 1 END " & _
                      "HAVING (a.Blocked = 0) ORDER BY No"
                myCommand.Connection = myConnection
                Dim da As New SqlDataAdapter
                da.SelectCommand = myCommand
                Dim ds As New DataSet
                myConnection.Open()
                da.Fill(ds, "products")
                myConnection.Close()
                Return ds.Tables("products")
25. September 2012 10:07
25. September 2012 11:43