Thursday, August 15, 2013

JD Edwards - How to create parent child relationship for Account master(F0901) Object AC


Change level of detail with temp table name.


DECLARE
    @db_name SYSNAME,
    @sql VARCHAR(1000),
    @databaseNM varchar(50),
    @ACOBJ int,
    @ACLDA int
    set @ACLDA=4
    drop table #temp1
    create table #temp1 (fld1 int,fld2 int) 
    
DECLARE db_cursor CURSOR FOR 
--SELECT Name FROM sys.databases where Name=@databaseNM
select ACOBJ  obj from  JDE_PRODUCTION.PRODDTA.F0909 where ACLDA=@ACLDA and acobj>00000 and acobj<100000   --and acobj=41110
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @db_name
WHILE (@@FETCH_STATUS = 0)
BEGIN
select @ACOBJ=MAX(ACOBJ)   from  JDE_PRODUCTION.PRODDTA.f0909 where  ACLDA=@ACLDA-1 and ACOBJ <(select MAX(ACOBJ)  from  JDE_PRODUCTION.PRODDTA.f0909 where ACOBJ=@db_name  and ACLDA=@ACLDA)
--select @ACOBJ=MAX(ACOBJ)  from  JDE_PRODUCTION.PRODDTA.f0909 where  ACLDA=6 and ACOBJ <(select MAX(ACOBJ)  from  JDE_PRODUCTION.PRODDTA.f0909 where ACOBJ=@db_name  and ACLDA=7)
Insert into #temp1 select @ACOBJ,@db_name
FETCH NEXT FROM db_cursor INTO @db_name
END
CLOSE db_cursor
DEALLOCATE db_cursor
--drop table #temp5
select * into #temp5  from #temp1
select *  from #temp1


--select * from #temp5
--select * from #temp6
--select * from #temp7
--select * from #temp8
--drop table  #temp4_1


select a7.fld1 A_071,a7.fld2  A_072,a8.fld1 A_081,a8.fld2 A_082  into #temp7_1 from #temp7 a7
left outer join  #temp8 a8 on  a7.fld2=a8.fld1

select fld1 A_061,fld2 A_062,A_071,A_072,A_081,A_082  into #temp6_1 from #temp7_1 a7 
left outer join  #temp6 a6 on  a6.fld2=a7.A_071

select fld1 A_051,fld2 A_052,A_061,A_062,A_071,A_072,A_081,A_082  into #temp5_1
from #temp6_1
left outer join  #temp5 a5 on  a5.fld2=A_061

select A_051,A_061,A_062,A_072, ISNULL(A_082,'')A_082 from #temp5_1

Tuesday, August 6, 2013

Extract all VBA code from Excel Workbook

Public Sub ExportModules()
    Dim bExport As Boolean
    Dim wkbSource As Excel.Workbook
    Dim szSourceWorkbook As String
    Dim szExportPath As String
    Dim szFileName As String
    'Dim cmpComponent As VBIDE.VBComponent

    ''' The code modules will be exported in a folder named.
    ''' VBAProjectFiles in the Documents folder.
    ''' The code below create this folder if it not exist
    ''' or delete all files in the folder if it exist.
    If FolderWithVBAProjectFiles = "Error" Then
        MsgBox "Export Folder not exist"
        Exit Sub
    End If
    
    On Error Resume Next
        Kill FolderWithVBAProjectFiles & "\*.*"
    On Error GoTo 0

    ''' NOTE: This workbook must be open in Excel.
    szSourceWorkbook = ActiveWorkbook.Name
    Set wkbSource = Application.Workbooks(szSourceWorkbook)
    
    If wkbSource.VBProject.Protection = 1 Then
    MsgBox "The VBA in this workbook is protected," & _
        "not possible to export the code"
    Exit Sub
    End If
    
    szExportPath = FolderWithVBAProjectFiles & "\"
    
    For Each cmpComponent In wkbSource.VBProject.VBComponents
        
        bExport = True
        szFileName = cmpComponent.Name

        ''' Concatenate the correct filename for export.
        Select Case cmpComponent.Type
            Case vbext_ct_ClassModule
                szFileName = szFileName & ".cls"
            Case vbext_ct_MSForm
                szFileName = szFileName & ".frm"
            Case vbext_ct_StdModule
                szFileName = szFileName & ".bas"
            Case vbext_ct_Document
                ''' This is a worksheet or workbook object.
                ''' Don't try to export.
                bExport = False
        End Select
        
        If bExport Then
            ''' Export the component to a text file.
            cmpComponent.Export szExportPath & szFileName
            
        ''' remove it from the project if you want
        '''wkbSource.VBProject.VBComponents.Remove cmpComponent
        
        End If
   
    Next cmpComponent

    MsgBox "Export is ready"
End Sub


Public Sub ImportModules()
    Dim wkbTarget As Excel.Workbook
    Dim objFSO As Scripting.FileSystemObject
    Dim objFile As Scripting.File
    Dim szTargetWorkbook As String
    Dim szImportPath As String
    Dim szFileName As String
    Dim cmpComponents As VBIDE.VBComponents

    If ActiveWorkbook.Name = ThisWorkbook.Name Then
        MsgBox "Select another destination workbook" & _
        "Not possible to import in this workbook "
        Exit Sub
    End If

    'Get the path to the folder with modules
    If FolderWithVBAProjectFiles = "Error" Then
        MsgBox "Import Folder not exist"
        Exit Sub
    End If

    ''' NOTE: This workbook must be open in Excel.
    szTargetWorkbook = ActiveWorkbook.Name
    Set wkbTarget = Application.Workbooks(szTargetWorkbook)
    
    If wkbTarget.VBProject.Protection = 1 Then
    MsgBox "The VBA in this workbook is protected," & _
        "not possible to Import the code"
    Exit Sub
    End If

    ''' NOTE: Path where the code modules are located.
    szImportPath = FolderWithVBAProjectFiles & "\"
        
    Set objFSO = New Scripting.FileSystemObject
    If objFSO.GetFolder(szImportPath).Files.Count = 0 Then
       MsgBox "There are no files to import"
       Exit Sub
    End If

    'Delete all modules/Userforms from the ActiveWorkbook
    Call DeleteVBAModulesAndUserForms

    Set cmpComponents = wkbTarget.VBProject.VBComponents
    
    ''' Import all the code modules in the specified path
    ''' to the ActiveWorkbook.
    For Each objFile In objFSO.GetFolder(szImportPath).Files
    
        If (objFSO.GetExtensionName(objFile.Name) = "cls") Or _
            (objFSO.GetExtensionName(objFile.Name) = "frm") Or _
            (objFSO.GetExtensionName(objFile.Name) = "bas") Then
            cmpComponents.Import objFile.Path
        End If
        
    Next objFile
    
    MsgBox "Import is ready"
End Sub

Function FolderWithVBAProjectFiles() As String
    Dim WshShell As Object
    Dim FSO As Object
    Dim SpecialPath As String

    Set WshShell = CreateObject("WScript.Shell")
    Set FSO = CreateObject("scripting.filesystemobject")

    SpecialPath = WshShell.SpecialFolders("MyDocuments")

    If Right(SpecialPath, 1) <> "\" Then
        SpecialPath = SpecialPath & "\"
    End If
    
    If FSO.FolderExists(SpecialPath & "VBAProjectFiles") = False Then
        On Error Resume Next
        MkDir SpecialPath & "VBAProjectFiles"
        On Error GoTo 0
    End If
    
    If FSO.FolderExists(SpecialPath & "VBAProjectFiles") = True Then
        FolderWithVBAProjectFiles = SpecialPath & "VBAProjectFiles"
    Else
        FolderWithVBAProjectFiles = "Error"
    End If
    
End Function

Function DeleteVBAModulesAndUserForms()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        
        Set VBProj = ActiveWorkbook.VBProject
        
        For Each VBComp In VBProj.VBComponents
            If VBComp.Type = vbext_ct_Document Then
                'Thisworkbook or worksheet module
                'We do nothing
            Else
                VBProj.VBComponents.Remove VBComp
            End If
        Next VBComp
End Function
 




How to find UDF value in P6 Primavira

select * from udfvalue
select * from udfcode
select * from udfvalue where udf_text like '%manager%'
select distinct udf_text from udfvalue where udf_text like '%IT Project Manager%'
select * from udfvalue where udf_text like '%Project Manager%'
select * from udfvalue where udf_type_id=330
user_field_330
sp_help projwbs

Monday, July 22, 2013

Excel VBA 2010 - Read a folder and load file name in SQL-Server 2008

Sub ListAllFile()
     

    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
    Dim cnt As Integer
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Set ws = Worksheets.Add
    'ActiveSheet.Range("C1").Value
    Set ws = Worksheets("Sheet1")
    cnt = 1
     
     'Get the folder object associated with the directory

    Set objFolder = objFSO.GetFolder("\\abcserver\Fin\Report Output")
    ws.Cells(1, 1).Value = "The files found in This Folder are:- " ' & objFolder.Name & "are:"
    
     'Loop through the Files collection
    For Each objFile In objFolder.Files
        ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
        'Debug.Print objFile
        rptPathName = objFile.Name
        Call InsertRecord(cnt, rptPathName)
    cnt = cnt + 1
    Next
     
     'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing
     
End Sub




Sub InsertRecord(strcnt, strFilePathName)
            Dim adoCN As ADODB.Connection
            Dim sConnString As String
            Dim sSQL As String
            Dim lRow As Long, lCol As Long
            Dim recnt As Integer
            Dim RecRow As Integer
            Dim tbl As Range
            Dim FileName
            Set adoCN = CreateObject("ADODB.Connection")
            sConnString = stADO
            adoCN.Open sConnString
            FileName = strFilePathName
            strFilePathName = ActiveSheet.Range("C1").Value & "\" & strFilePathName
            
                         Dim MyString As String

                                        sSQL = "insert into budget.dbo.tbltempReport  select " & strcnt & ",'" & Replace(strFilePathName, "'", "''") & "'" & ""

                                       Debug.Print sSQL
                          adoCN.Execute sSQL
            adoCN.Close
            Set adoCN = Nothing
End Sub

Table structure
CREATE TABLE [dbo].[tbltempReportOutPD](
[ID] [int] NULL,
[ReportName] [nvarchar](1000) NULL
) ON [PRIMARY]

Shutdown PC command line

  shutdown /s


Wednesday, July 17, 2013

Run VBA reports in Multiple Instances - Shell

Sub RunExcelMultiple(RecCnt)

    Dim lPid As Long, i As Long
    Dim sRemoteWbName As String, sExeName As String, sParams As String
    sExeName = "excel.exe"
    
    sRemoteWbName = """" & ActiveWorkbook.FullName & """"
    
    sParams = " /e" & " -!- " & " "
    
    If (RecCnt < 11) Then
      lPid = Shell(sExeName & sParams & sRemoteWbName, vbHide)
    Else
        For ShellInstance = 1 To Round(WorksheetFunction.Min(8, RecCnt / 4), 0)
            lPid = Shell(sExeName & sParams & sRemoteWbName, vbHide)
        Next ShellInstance
    End If
    
       

End Sub

Saturday, May 18, 2013

Cannot connect to MS SQL 2008 R2 locally or remotely - Error 53

  • A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)

    solution

    Error 53 sql server 2008 r2


    To enable a server network protocol

    1.

    In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration.


    2.

    In the console pane, click Protocols for <instance name>.


    3.

    In the details pane, right-click the protocol you want to change, and then click Enable or Disable.


    4.

    In the console pane, click SQL Server Services.


    5.

    In the details pane, right-click SQL Server (<instance name>), and then click Restart, to stop and restart the SQL Server service.


    http://msdn.microsoft.com/en-us/library/ms191294.aspx




Sunday, May 5, 2013

Login from SQL-server in ASP.Net C#

    private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
    {

        bool boolReturnValue = false;

        string strConnection = ConnectionString;

        SqlConnection Connection = new SqlConnection(strConnection);
        string strUserID = UserName;
        String strSQL = "select * from UserDetails where UDUSRID=\'" + (strUserID + "\'");
        SqlCommand command = new SqlCommand(strSQL, Connection);
        SqlDataReader Dr;
        Connection.Open();
        Dr = command.ExecuteReader();
        while (Dr.Read())
        {
            string UserNameDB = Dr["UDUSRID"].ToString();
            string PasswordDB = Dr["UDPASSWD"].ToString();
            //  string UserRoleDB = Dr["UDROLE"].ToString();


            if ((UserName == UserNameDB.TrimEnd().TrimStart()) & (Password == PasswordDB.TrimEnd().TrimStart()))
            {
                Session["Usrid"] = UserNameDB;
                Session["Uspasswd"] = PasswordDB;
                //    Session["Usrole"] = UserRoleDB;
                //  Response.Write(Session["Usrole"]);
                // Response.End();

                boolReturnValue = true;
                break;

            }

        }

        Dr.Close();

        return boolReturnValue;

    }

Send email in a format c#

    void sndemail()
    {
        MailMessage objEmail = new MailMessage();
        objEmail.To = "xxxxx@xxxxxx.com";//Session["OEMAL"].ToString().Trim();//Emald.ToString().Trim();//txtTo.Text;
        //objEmail.To = "dostind@gmail.com";//Session["OEMAL"].ToString().Trim();//Emald.ToString().Trim();//txtTo.Text;
   
        //objEmail.From = "rajeev@xxxxxx.net";
        objEmail.From = "noreply@xxxxxx.com";

        //objEmail.Cc = txtCc.Text;
        objEmail.Subject = "HI -- Notification";// +Strrslt.ToString();
        //Response.Write(Session["oename"].ToString());  HI Quiz – Course Completion Notification
        //Response.End();
        //objEmail.Body = "<table border=1 bgcolor=#F3EFE0><tr><td>Date :</td><td><b>" + DateTime.Today.ToLongDateString() + "</td></tr><tr><td>Exam Id:</td><td>" + Request["id"].ToString() + "</td></tr><tr><td>Trainee:</td><td> </b> " + Session["repname"].ToString() + "</td></tr><tr><td>Total Correct:</td><td>" + cortans + " Out of:-" + totrec + "</td></tr><tr><td>Owner: </td><td>" + Session["oename"].ToString() + "</td></tr><tr><td>Program:</td><td>Home Impovement</td></tr><tr><td><b>Result:</b></td><td><b>" + Strrslt.ToString() + "</b></td></tr>  </table>";
        objEmail.Body = "<b>The following trainee has completed the Home Improvement training course:</b><br><br>";
        objEmail.Body += "<table border=0 width=50%   bgcolor=#CCCCCC cellpadding=10 ><tr><td>Trainee :</td><td><b>" + Session["repname"].ToString() + "</td></tr><tr><td>Market:</td><td>" + Session["oeMarket"].ToString() + "</td></tr><tr><td>ICD:</td><td> </b> " + Session["owniNam"].ToString().Replace("'"," ") + "</td></tr><tr><td>Date:</td><td>" + DateTime.Today.ToLongDateString() + "</td></tr><tr><td>Total Correct: </td><td>" + cortans + " Out of:-" + totrec + "</td></tr><tr><td><b>Status:</b></td><td><b>" + Strrslt.ToString() + "</b></td></tr>  </table>";
      
        //objEmail.Body = Label4.Text;

        //objEmail.Priority = MailPriority.High;
        objEmail.BodyFormat = MailFormat.Html;//MailFormat.Html; Session["oeMarket"]
        // Make sure you have appropriate replying permissions from your local system

       SmtpMail.SmtpServer = "10.0.10.123";
        //SmtpMail.SmtpServer = "localhost";

        try
        {
            SmtpMail.Send(objEmail);


        }
        catch (Exception exc)
        {
            Response.Write("Send failure: " + exc.ToString());
        }

    }


    private string ConnectionString
    {
        get
        {
            string connectionString = ConfigurationManager.ConnectionStrings["smdbConnectionString51"].ConnectionString;
            return connectionString;
        }
    }

Tuesday, April 23, 2013

Extract Excel input string "+"

DECLARE @test varchar(100) = '+HARIA+123+MALE+STUDENT+HOUSEWIFE+jhgjh+54545+hgdfjhg+xxxxc'

SELECT TOP 8000
    Num
INTO
    #Number
FROM
    (
    SELECT
       ROW_NUMBER() OVER (ORDER BY c1.object_id) AS Num
    FROM
       sys.columns c1, sys.columns c2, sys.columns c3
    ) N

SELECT
    ROW_NUMBER() OVER (ORDER BY Num) AS Rank,
    LTRIM(RTRIM(SUBSTRING(@test,
                          Num,
                          CHARINDEX('+', @test + '+', Num) - Num
                ))) AS Value
FROM
    #Number
WHERE
    Num <= LEN (@test)
    AND
    SUBSTRING('+' + @test, Num, 1) = '+'

DROP TABLE #Number
Source :stackoverflow

Sunday, April 7, 2013

Excel vba 2010 browse select folder and open file

Private Sub CommandButton1_Click()

Dim myfile As Variant
Dim counter As Integer
Dim path As String
myfolder = "c:\tmp\"
ChDir myfolder
myfile = Application.GetOpenFilename(, , , , True)
counter = 1
If IsNumeric(myfile) = True Then
MsgBox "No files selected"
End If
While counter <= UBound(myfile)
path = myfile(counter)
Workbooks.Open path
counter = counter + 1
Wend

End Sub