Friday, 28 September 2012

Changing table column size

alter table table_name alter column column_name char(500)

How to restrict textbox to enter 500 characters only after that if we insert any character it will display pop up message

Design page
<asp:TextBox ID="txtreqtitle" runat="server" CssClass="textCopy" Width="260px" Columns="25"
 MaxLength="500" TextMode="MultiLine"  Rows="3" Height="55px"  ></asp:TextBox>

aspx.cs page
this.txtreqtitle.Attributes.Add("onKeyPress", "return textCounter(this, 500);");
this.txtreqtitle.Attributes.Add("onKeyUp", "return textCounter(this, 500);");

Tuesday, 25 September 2012

javascript on radio button click


 <script type="text/javascript">

function Enable_PromProg() {
            debugger;
            var rdbPromProgYes = document.getElementById("<%=rdbPromProgYes.ClientID%>");
            var rdbPromProgNo = document.getElementById("<%=rdbPromProgNo.ClientID%>");
            var trPromotional = document.getElementById("<%=trPromotional.ClientID%>");
            if (rdbPromProgYes != null) {

                trPromotional.style.display = 'none';
                if (rdbPromProgYes.checked != true && rdbPromProgNo.checked != true) {

                    trPromotional.style.display = 'none';
                    //txtPromotionalDesc.disabled = true;
                }
                else if (rdbPromProgYes.checked == true) {
                    trPromotional.style.display = '';
                    //txtPromotionalDesc.disabled = false;
                }
                else if (rdbPromProgNo.checked == true) {

                    trPromotional.style.display = 'none';
                }
            }
        }


</script>

<asp:RadioButton ID="rdbPromProgYes" runat="server" Text="Yes" GroupName="PromProg"
                                                onclick="javascript:Enable_PromProg();" />

Thursday, 6 September 2012

Case statement in SQL

"PaymentReleaseDate"=
Case ISNULL(Convert(Varchar(20),tgr.ap_print_date,101),'') when '' then
( Select milestone_release_date from t_grant_milestones where grant_id= tgr.grant_id and entry_id=tgm.entry_id)
else tgr.ap_print_date 
End AS  PaymentReleaseDate,

Tuesday, 21 August 2012

Query String in ASP.Net


pass the value through url from previous page
 int FromID = Convert.ToInt32(Session["User_Id"]);
 string url = "EmployeeDetails.aspx?From_ID=" + FromID.ToString();
 Response.Redirect(url);

Accept the value which passed by url 

 string From_ID = Request.QueryString["From_ID"].ToString();


Friday, 17 August 2012

view Delivery formate usage

Create view [dbo].[Vw_Delivery_format_usage]
as

Select distinct grant_id,delivery_format_name,approved_amount,date_submitted From (

Select t1.grant_id,
case when t1.TotalValue=1 then tad.delivery_format_name
else 'MultiView'
end as delivery_format_name
,approved_amount
,g.date_submitted,TotalValue
From (
Select COUNT(delivery_format_name) as TotalValue,grant_id from (
        select
        distinct a.grant_id,
        tad.delivery_format_name,
        g.approved_amount
        from t_grant_request g
        inner join t_grant_activity a on a.grant_id=g.grant_id
        inner join t_activity_delivery_format tad on tad.delivery_format_id=a.delivery_format_id
)t
group by grant_id
)t1 inner join
t_grant_request g on t1.grant_id=g.grant_id
inner join t_grant_activity a on a.grant_id=g.grant_id
and g.approved_amount is not null
and approved_amount not in (0) 
and g.grant_status not in ('not submitted','cancelled','denied','rejected')
inner join t_activity_delivery_format tad on tad.delivery_format_id=a.delivery_format_id
)t2

Friday, 8 June 2012

return url issue


add this code to the global.asax page

void Application_BeginRequest(object sender, EventArgs e)
   {
       string path = HttpContext.Current.Request.Url.PathAndQuery;
       string pagequery = path.Substring(path.LastIndexOf("/") + 1);
       string[] pagequery_Elements = pagequery.Split('?');
       string ReturnUrl = pagequery_Elements[pagequery_Elements.Length - 1];

       if (ReturnUrl.Contains("ReturnUrl"))
       {        
           Response.Redirect("~/login.aspx", true);
       }
   }

Friday, 18 May 2012

hide browser back button

<script type="text/javascript" language="javascript">
    javascript: window.history.forward(1);
    </script>

Friday, 16 March 2012

password

create Proc PMP_GetLastThreePassword  --763,'ani763um'
@UserID int, 
@Password varchar(500) 
AS 
BEGIN 
 
  select COUNT(*) from
  (
 
  Select top 3 new_value,profile_id  From PMP_User_Profile_History where userid=@UserID
  and column_name='password'  order by profile_id desc 
  ) t where new_value = @Password
 

 
END

Monday, 5 March 2012

Partial serach query

CREATE PROCEDURE [dbo].[PMP_GetOrganizationSearchInfowithrows_BGCM_BestMatch]  
--1,20,' ',' and c.Full_Name like ''co%''' , ' and c.Full_Name like ''%co%'' and c.Full_Name not like ''co%'''                        
@startRowIndex int ,                                 
@maximumRows int,                                                
@whereClause VARCHAR(max), 
@ExactSearchClause VARCHAR(1000), 
@BestSearchClause VARCHAR(1000), 
@PartialSearchClause VARCHAR(1000)                                                     
AS                                                                       
BEGIN                                   
           
DECLARE @LowerBound INT                                 
DECLARE @UpperBound INT                                 
SET @LowerBound = (@maximumRows * (@startRowIndex - 1) + 1)                                 
SET @UpperBound =  @maximumRows * @startRowIndex            
           
DECLARE @SQLQryStr VARCHAR(8000)           
DECLARE @SQLCommand VARCHAR(8000)     
DECLARE @SQLQry VARCHAR(8000)    
DECLARE @SQLQryNew VARCHAR(8000)     
 
Set @SQLQryStr = '            
IF EXISTS (SELECT table_name                    
                 FROM   information_schema.tables                    
                 WHERE  table_name = ''tempExactMatch'')                    
        DROP TABLE tempExactMatch   
SELECT ROW_NUMBER() over( Order by c.Full_Name ) AS RowNumber,                   
   C.BGCM_ID                    
  ,ISNULL(C.STAR_ID,0) AS [OrganizationID]                  
  ,ISNULL(FT.FacilityType_ID ,0) AS FacilityType_ID                
  ,FT.FacilityType_Name                  
  ,c.Full_Name                     
  ,A.Address_Line_1                                                 
  ,A.Address_Line_2                                                 
  ,A.City                 
  ,isnull(sm.State_Id ,0) AS [Address_State_ID]                  
  ,SM.State_Name                   
  ,sm.State_initials +''- ''+ sm.State_Name as State_Province                                     
  ,A.Postal_Area                 
  ,isnull(cnt.Country_Id ,0) as Country_Id                                  
  ,cnt.Country_Name,A.State          
  INTO tempExactMatch                         
 FROM PMP_BGCMCustomer c                                                 
 inner  JOIN PMP_BGCMAddress A ON c.BGCM_ID = A.BGCM_ID                                     
 LEFT OUTER JOIN PMP_Country cnt on a.Country=cnt.Country_Name                    
 LEFT OUTER JOIN PMP_StateMaster sm ON A.State_Province = SM.State_initials                
 LEFT OUTER JOIN PMP_FacilityType FT ON c.Customer_Type = FT.FacilityType_Name                               
 WHERE  1=1  --and cust_type=''Org''  
 and c.First_name is null and rtrim(ltrim(c.full_Name))!='''' and c.full_Name is not null  '                                               
                
SET @SQLQryStr = @SQLQryStr + @whereClause + @ExactSearchClause  
EXEC(@SQLQryStr) 
  
Declare @Cnt int 
Select @Cnt=ISNULL(Max(RowNumber),0) From tempExactMatch 
                          
                                 
SET @SQLCommand = '            
IF EXISTS (SELECT table_name                    
                 FROM   information_schema.tables                    
                 WHERE  table_name = ''tempBestMatch'')                    
        DROP TABLE tempBestMatch   
SELECT ' + Convert(Varchar(10),@Cnt) + '+ROW_NUMBER() over( Order by c.Full_Name ) AS RowNumber,                   
   C.BGCM_ID                    
  ,ISNULL(C.STAR_ID,0) AS [OrganizationID]                  
  ,ISNULL(FT.FacilityType_ID ,0) AS FacilityType_ID                
  ,FT.FacilityType_Name                  
  ,c.Full_Name                     
  ,A.Address_Line_1                                                 
  ,A.Address_Line_2                                                 
  ,A.City                 
  ,isnull(sm.State_Id ,0) AS [Address_State_ID]                  
  ,SM.State_Name                   
  ,sm.State_initials +''- ''+ sm.State_Name as State_Province                                     
  ,A.Postal_Area                 
  ,isnull(cnt.Country_Id ,0) as Country_Id                                  
  ,cnt.Country_Name,A.State          
  INTO tempBestMatch                         
 FROM PMP_BGCMCustomer c                                                 
 inner  JOIN PMP_BGCMAddress A ON c.BGCM_ID = A.BGCM_ID                                     
 LEFT OUTER JOIN PMP_Country cnt on a.Country=cnt.Country_Name                    
 LEFT OUTER JOIN PMP_StateMaster sm ON A.State_Province = SM.State_initials                
 LEFT OUTER JOIN PMP_FacilityType FT ON c.Customer_Type = FT.FacilityType_Name                               
 WHERE  1=1  --and cust_type=''Org''  
 and c.First_name is null and rtrim(ltrim(c.full_Name))!='''' and c.full_Name is not null  '                                               
                
SET @SQLCommand = @SQLCommand + @whereClause + @BestSearchClause  
EXEC(@SQLCommand) 
  
Declare @Count int 
Select @Count=ISNULL(Max(RowNumber),0) From tempBestMatch 
 
SET @SQLQry = '     
IF EXISTS (SELECT table_name                    
         FROM   information_schema.tables                    
         WHERE  table_name = ''tempPartialMatch'')                    
  DROP TABLE tempPartialMatch            
SELECT ' + Convert(Varchar(10),@Count) + '+ROW_NUMBER() over( Order by c.Full_Name ) AS RowNumber,                   
   C.BGCM_ID                    
  ,ISNULL(C.STAR_ID,0) AS [OrganizationID]                  
  ,ISNULL(FT.FacilityType_ID ,0) AS FacilityType_ID                
  ,FT.FacilityType_Name                  
  ,c.Full_Name                     
  ,A.Address_Line_1                                                 
  ,A.Address_Line_2                                                 
  ,A.City                 
  ,isnull(sm.State_Id ,0) AS [Address_State_ID]                  
  ,SM.State_Name                   
  ,sm.State_initials +''- ''+ sm.State_Name as State_Province                                     
  ,A.Postal_Area                 
  ,isnull(cnt.Country_Id ,0) as Country_Id                                  
  ,cnt.Country_Name,A.State          
  INTO tempPartialMatch                         
 FROM PMP_BGCMCustomer c                                                 
 inner  JOIN PMP_BGCMAddress A ON c.BGCM_ID = A.BGCM_ID                                     
 LEFT OUTER JOIN PMP_Country cnt on a.Country=cnt.Country_Name                    
 LEFT OUTER JOIN PMP_StateMaster sm ON A.State_Province = SM.State_initials                
 LEFT OUTER JOIN PMP_FacilityType FT ON c.Customer_Type = FT.FacilityType_Name                               
 WHERE  1=1  --and cust_type=''Org''  
 and c.First_name is null and rtrim(ltrim(c.full_Name))!='''' and c.full_Name is not null  '                                               
                
SET @SQLQry = @SQLQry + @whereClause + @PartialSearchClause  
EXEC(@SQLQry) 
 
 
SET @SQLQryNew = '              
IF EXISTS (SELECT table_name                      
                 FROM   information_schema.tables                      
                 WHERE  table_name = ''Search_Organization'')                      
        DROP TABLE Search_Organization 
SELECT *  
INTO Search_Organization  
FROM ( 
 SELECT * FROM tempExactMatch  
 UNION 
 SELECT * FROM tempBestMatch  
 UNION 
 SELECT * FROM tempPartialMatch )t ' 
 
SET @SQLQryNew = @SQLQryNew +'  order by RowNumber ASC '                                  
-- Table[0]-- Get the records --------------------------------------             
                                 
set @SQLQryNew=@SQLQryNew + ' SELECT * FROM Search_Organization                                                    
 WHERE RowNumber BETWEEN  ' + CAST(@LowerBound AS VARCHAR(10)) + ' AND ' + CAST(@UpperBound  AS VARCHAR(10))                               
           
-- Table[1]-- Get the total rows --------------------------------------  
set @SQLQryNew=@SQLQryNew + ' Select Count(*) FROM Search_Organization '            
           
PRINT @SQLQryNew             
EXEC(@SQLQryNew)             
                             
END

Thursday, 1 March 2012

split the value of the variable

 string[] DynamicFilePathNameArray = FileName.Split('.');
 string DynamicFilePathName = DynamicFilePathNameArray[0]+".txt";

Tuesday, 28 February 2012

print code

<asp:ImageButton OnClientClick="javascript:ClickPrint();" ImageUrl="images/btn_print.gif"
                    ID="btnPrint" runat="server"/>

 <script language="javascript" type="text/javascript">
          function ClickPrint() {

              //ISP-CheckRequest
            window.print();
            document.form1.btnPrint.style.visibility = 'hidden';
            document.form1.btnClose.style.visibility = 'hidden';
            document.form1.btnPrevious.style.visibility = 'hidden';
            document.form1.btnNext.style.visibility = 'hidden';
       
            document.form1.submit();
            }
           
            function ClickClose()
            {
            window.close();
            }
        </script>

Anil

Tuesday, 21 February 2012

datalist wrap column field

 <td>
    <div style="word-wrap: break-word; width: 100px" >
                        <%# Eval("MName")%>
     </div>
 </td>


also set datalist width=100%

Thursday, 16 February 2012

SSIS reading multiple xml files from folder

http://stackoverflow.com/questions/6956409/ssis-reading-multiple-xml-files-from-folder

How to create ssis package which copies all files into new folder

http://stackoverflow.com/questions/7139172/how-to-create-ssis-package-which-copies-all-files-into-new-folder

Monday, 13 February 2012

how to substring one comma saperated column values

Select            
  @FirstName=Substring(@RecipientName,1,charindex(',',@RecipientName,1)-1),           
  @LastName=Substring(@RecipientName,charindex(',',@RecipientName,1)+1,len(@RecipientName)) 

how to chek comma in values

DECLARE @Pos int           
           
    SET @RecipientName = LTRIM(RTRIM(@RecipientName))           
    SET @Pos = CHARINDEX(',', @RecipientName, 1)           
 IF( @Pos > 0) 

how to replace spaces and compare where condition

Declare @Credential varchar(500)
SET @Credential = 'MediCAl  Doctor'
 select Credentials_Id from PMP_Credentials where REPLACE(Description,' ','')= REPLACE(@Credential,' ','')