Pages

Subscribe:

Tuesday, 1 August 2017

How to check date is valid or not using oracle

create or replace FUNCTION IS_VALIDDATE(v_date IN VARCHAR2) RETURN NUMBER IS
    v_date1 DATE;
BEGIN

    SELECT TO_DATE(substr(v_date,0,10),'mm/dd/yyyy') INTO v_date1 FROM DUAL;
        RETURN 1;
    Exception WHEN Others THEN
        RETURN 0;
END;

to check---

select IS_VALIDDATE('04/21/2015') as V_DATE from dual;

How to create cursor in procedure using oracle

create or replace PROCEDURE PROC_TESTPROCEDURENAME
(
REF_CURSOR         OUT      SYS_REFCURSOR,
OP_strException      OUT      VARCHAR2
)
AS
V_COUNT INTEGER:=0;
cursor c is select id from TBL_USERMASTER;
tmp INTEGER;
BEGIN
    open c;
    LOOP EXIT when c%NOTFOUND;
    FETCH c into tmp;
    V_COUNT:=0;
   select count(*) into V_COUNT from TBL_MAPPINGUSERDETAIL where fkUserid=tmp;
   if V_COUNT=0 then
   insert into TBL_MAPPINGUSERDETAIL(id,name,mobile,fkUserid,created_date)
   select SEQ_TBL_MAPPINGUSERDETAIL.NEXTVAL,NAME,MOBILE_NO,SEQID,sysdate from TBL_USERMASTER where id =tmp;
  end if;  
commit;
 
  END Loop;
close c;

  OPEN REF_CURSOR FOR
  select id,name,mobile,fkUserid from TBL_MAPPINGUSERDETAIL order by name;
  OP_strException:='';
 
  exception
        when others then
        OP_strException:= SUBSTR(SQLERRM, 1, 100);
       
        -- Log Table Maintain
END;

Loop in oracle

BEGIN
For i in (select id, name, mobile from testtable)
LOOP
Update mappingtesttable set name = i.name,mobile_no=i.mobile where fkid = i.id;
END LOOP;
END;

How to Create proxy class

C:\Program Files\Microsoft Visual Studio 10.0\VC> wsdl   /out:location to save proxy class(D:\proxyclass.cs) location to consume service or wsdl file(D:\test.wsdl)

Sunday, 30 August 2015

Resignation letter Sample

Dear xxx ,

Please accept this letter of resignation from the position of
Technical Lead, 30 days from today. My last day at [Company Name]will be
29-Sep-2015.

I have accepted a position with another company that will further my
growth and development in my career. I have enjoyed working at [Company Name]
and will miss my colleagues. However, this new position will challenge
my growth and further my career.

During the next one month, I am willing to help you in any way to make
the transition as smooth as possible. This includes assisting in
recruiting and training my replacement. Please let me know if there is
anything specific that you would like me to do.

Again, it has been a pleasure working as a part of your company.

Best regards,

Manish Kumar Srivastava

Thursday, 26 February 2015

Autocomplete on masterpage

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
    <asp:TextBox ID="txtAutoComplete" runat="server" />
    <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" DelimiterCharacters=""
        Enabled="True" ServicePath="SaveSelectedOption.asmx" ServiceMethod="GetCompletionList"
        TargetControlID="txtAutoComplete" MinimumPrefixLength="1" CompletionInterval="10"
        EnableCaching="true" CompletionSetCount="12">
    </asp:AutoCompleteExtender>

 [WebMethod]
        public string[] GetCompletionList(string prefixText, int count)
        {
            if (count == 0)
            {
                count = 10;
            }
            DataTable dt = GetRecords(prefixText);
            List<string> items = new List<string>(count);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = dt.Rows[i][0].ToString();
                items.Add(strName);
            }
            return items.ToArray();
        }

        public DataTable GetRecords(string strName)
        {
            string strConn = ConfigurationManager.ConnectionStrings["jsupportconnectionstring"].ConnectionString;
            SqlConnection con = new SqlConnection(strConn);
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Parameters.AddWithValue("@Name", strName);
            cmd.CommandText = "select CommentEmpId from LT_CommentReadHistory where CommentEmpId like '%'+@Name+'%'";
            DataSet objDs = new DataSet();
            SqlDataAdapter dAdapter = new SqlDataAdapter();
            dAdapter.SelectCommand = cmd;
            con.Open();
            dAdapter.Fill(objDs);
            con.Close();
            return objDs.Tables[0];
        }
using System.Configuration;
using System.Data.SqlClient;

Sunday, 8 February 2015

Save data through XML

 StringBuilder objBuilder = GetCheckedSitemap();
Role objRole = new Role();
          objRole.AddedBy = "admin";
          objRole.LastModBy = "admin";
          objRole.RoleID = roleID;
          objRole.XMLData = objBuilder.ToString();

 private StringBuilder GetCheckedSitemap()
    {
    
        StringBuilder objBuilder = new StringBuilder();
        objBuilder.Append("<?xml version=\"1.0\"?>");
        objBuilder.Append("<Root>");
  objBuilder.Append("<sitemaprole roleid=\"" + roleID + "\" SiteMapID=\"" + row1["NavId"] + "\"/>");
   objBuilder.Append("</Root>");

        return objBuilder;
    }

proc
@XMl xml=null


 update tblUwkrn  set flow= flow+ '','' + @flow
                         ,StaffId=@StaffId
                         ,StaffDate=GETDATE()
                         ,StaffStatus=@StaffStatus
                         ,AsmStatus=@AsmStatus
         from tblUwkrn inner join
         @XMl.nodes(''UwkrnList'')r(item)
        on tblUwkrn.uwkrn=item.value(''@UwkrnNo'',''nvarchar(100)'')               
       and eventid=@EventId and AsmId=@AsmId and confirm_status=''Yes''

CREATE PROCEDURE[dbo].[usp_ADM_SaveSiteMapRole]
(
   
    @RoleID varchar(50),
   
    @XMLData varchar(max),
    @AddedBy varchar(50),
    @LastModBy varchar(50),
    @EventId nvarchar(50)
)

AS
BEGIN

BEGIN TRAN SaveSiteMapRole
 BEGIN TRY
   
    DECLARE @hDoc int
    DECLARE @Error int   

    EXEC sp_xml_preparedocument @hDoc OUTPUT,@XMLData

    DELETE FROM ADM_SiteMapRole
    WHERE RoleID=@RoleID and EventId=@EventId

    SELECT @EventId as eventId, roleid,sitemapid,1 as IsActive,@AddedBy as AddedBy,GETDATE() as AddedDTM,
        @LastModBy as LastModBy,GETDATE() as LastModDTM
    INTO #ADM_SiteMapRole
    FROM OpenXML(@hDoc,''/Root/sitemaprole'')
    WITH (
            roleid varchar(50) ''@roleid'',
            sitemapid int ''@SiteMapID''       
         )
       
         declare
         @eventId1 varchar(50),
         @roleid1 varchar(50),
         @sitemapid1 int,       
         @IsActive1 bit,
         @AddedBy1 varchar(50),
         @AddedDTM1 datetime,
         @LastModBy1 varchar(50),
         @LastModDTM1 datetime
       
       
        DECLARE sr_cursor CURSOR LOCAL FOR
            SELECT eventId,roleid,sitemapid,IsActive,AddedBy,AddedDTM,LastModBy,LastModDTM
            FROM #ADM_SiteMapRole                
        OPEN sr_cursor;
        FETCH NEXT FROM sr_cursor INTO @eventId1, @roleid1,@sitemapid1,@IsActive1,@AddedBy1,@AddedDTM1,@LastModBy1,@LastModDTM1
            WHILE @@FETCH_STATUS = 0
            BEGIN
                --login here
                if not exists(select 1 from ADM_SiteMapRole where RoleID=@roleid1 and SiteMapID=@sitemapid1 and IsActive=@IsActive1 and EventId= @eventId1)
                begin
                    --insert
                    INSERT INTO ADM_SiteMapRole(EventId,RoleID,SiteMapID,IsActive,AddedBy,AddedDTM,LastModBy,LastModDTM)
                    SELECT @eventId1, @roleid1,@sitemapid1,@IsActive1,@AddedBy1,@AddedDTM1,@LastModBy1,@LastModDTM1
                    --find all parent id and insert for them 
                    declare @t1  as table
                    (
                        id int not null identity(1,1),
                        sitemapid int,
                        parentid int                   
                    )
                   
                    insert into @t1(sitemapid,parentid )
                    select sitemapid,parentid
                    from dbo.func_ADM_GetParentsOfId(@sitemapid1, @eventId1) where sitemapid <> @sitemapid1
                   
                    declare @count int
                    declare @sid int
                    set @count=1
                    while ( @count <= (select MAX(id) from @t1) )
                    begin                   
                        select @sid=sitemapid from @t1 where id=@count
                        if not exists(select 1 from ADM_SiteMapRole where RoleID=@roleid1 and SiteMapID=@sid and IsActive=@IsActive1 and EventId=@eventId1)
                        begin
                            INSERT INTO ADM_SiteMapRole(EventId,RoleID,SiteMapID,IsActive,AddedBy,AddedDTM,LastModBy,LastModDTM)
                            SELECT @eventId1, @roleid1,@sid,@IsActive1,@AddedBy1,@AddedDTM1,@LastModBy1,@LastModDTM1
                        end                       
                        set @count = @count + 1
                    end     
                end               
                FETCH NEXT FROM sr_cursor INTO @eventId1, @roleid1,@sitemapid1,@IsActive1,@AddedBy1,@AddedDTM1,@LastModBy1,@LastModDTM1
            END
        CLOSE sr_cursor;
        DEALLOCATE sr_cursor;      

    --ERROR HANDLER
    SET @Error = @@error
    IF (@Error <> 0)
    BEGIN
        exec sp_xml_removedocument @hDoc
        RETURN
    END   

    drop table #ADM_SiteMapRole
    exec sp_xml_removedocument @hDoc
   
    COMMIT TRAN SaveSiteMapRole
 end Try
 BEGIN CATCH

 ROLLBACK TRAN SaveSiteMapRole
 close  SaveSiteMapRole
 SELECT ERROR_LINE(),ERROR_NUMBER(),ERROR_SEVERITY(),ERROR_STATE(),ERROR_PROCEDURE()
,ERROR_MESSAGE()
 END CATCH

END