Tuesday, 3 September 2013

How to calculate quarters in sql

Here are a few uses of the DATEADD date function:
Usage #1 : Get the Date Part of a DATETIME Value
SELECT DATEADD(DD, DATEDIFF(DD, 0, GETDATE()), 0) AS [Date Part Only]
Usage #2 : Get the First Day of the Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0) AS [First Day of the Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()), 0) AS [First Day of the Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0) AS [First Day of the Year]
Usage #3 : Get the Last Day of the Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 1, 0) - 1 AS [Last Day of the Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()) + 1, 0) - 1 AS [Last Day of the Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0) - 1 AS [Last Day of the Year]
Usage #4 : Get the First Day of the Following Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 1, 0) AS [First Day of Next Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()) + 1, 0) AS [First Day of Next Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 1, 0) AS [First Day of Next Year]
Usage #5 : Get the Last Day of the Following Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) + 2, 0) - 1 AS [Last Day of Next Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()) + 2, 0) - 1 AS [Last Day of Next Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) + 2, 0) - 1 AS [Last Day of Next Year]
Usage #6 : Get the First Day of the Previous Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) - 1, 0) AS [First Day Of Previous Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()) - 1, 0) AS [First Day Of Previous Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()) - 1, 0) AS [First Day Of Previous Year]
Usage #7 : Get the Last Day of the Previous Month, Quarter and Year
SELECT DATEADD(MM, DATEDIFF(MM, 0, GETDATE()), 0) - 1 AS [Last Day of Previous Month]
SELECT DATEADD(Q, DATEDIFF(Q, 0, GETDATE()), 0) - 1 AS [Last Day of Previous Quarter]
SELECT DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0) - 1 AS [Last Day of Previous Year]



DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)),@mydate),101) ,
'Last Day of Previous Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),101) AS Date_Value,
'First Day of Current Month' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),@mydate,101) AS Date_Value, 'Today' AS Date_Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),101) ,
'Last Day of Current Month'
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))-1),DATEADD(mm,1,@mydate)),101) ,
'First Day of Next Month'

--------------------------------------------------------------------------------------------------

----TodaySELECT GETDATE() 'Today'
----YesterdaySELECT DATEADD(d,-1,GETDATE()) 'Yesterday'
----First Day of Current WeekSELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) 'First Day of Current Week'
----Last Day of Current WeekSELECT DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6) 'Last Day of Current Week'
----First Day of Last WeekSELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),0) 'First Day of Last Week'
----Last Day of Last WeekSELECT DATEADD(wk,DATEDIFF(wk,7,GETDATE()),6) 'Last Day of Last Week'
----First Day of Current MonthSELECT DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0) 'First Day of Current Month'
----Last Day of Current MonthSELECT DATEADD(ms,- 3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE())+1,0))) 'Last Day of Current Month'
----First Day of Last MonthSELECT DATEADD(mm,-1,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0)) 'First Day of Last Month'
----Last Day of Last MonthSELECT DATEADD(ms,-3,DATEADD(mm,0,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))) 'Last Day of Last Month'
----First Day of Current YearSELECT DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0) 'First Day of Current Year'
----Last Day of Current YearSELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0))) 'Last Day of Current Year'
----First Day of Last YearSELECT DATEADD(yy,-1,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0)) 'First Day of Last Year'
----Last Day of Last YearSELECT DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0))) 'Last Day of Last Year'

Source: Kreato Crm





Monday, 2 September 2013

How to inspect HTML elements in the browser

Internet explorer

Check whether the Developer Toolbar is installed on your machine. If you are using IE8+, this tool is already integrated in your browser. Otherwise, you need to install it manually. If the Developer Tool is installed, perform the following steps:
1. Execute Developer Toolbar by pressing the F12 key on your keyboard. Alternatively, click the Tools -> F12 Developer tools menu as shown below.
2. The Developer Tools window will be displayed;
3. Click the Select element button;
4. Click an element on the page;
5. A corresponding HTML element will be selected in the HTML window;
6. Now we know that the CSS rule with the “testRule” name is applied to the element;
7. Find this rule in the Style window as shown below:
Firefox
The Firebug add-on is used for this purpose. Check whether this tool is installed on your machine and perform the following steps:
1. Execute Firebug by pressing the F12 key on your keyboard. Alternatively, click the Tools -> Web Developer -> Firebug -> Open Firebug menu as shown below.
2. The Firebug window will be displayed;
3. Click the button that is shown below to inspect a corresponding element;
4. Click the element on the page;
5. A corresponding HTML element will be selected in the HTML window;
6. Determine the rule name as shown above;
7. Find this rule in the Style window as shown below:
Chrome
Use Developer Tools to accomplish this task.
1. Execute Developer Tools by pressing the F12 key on your keyboard. Alternatively, click the Menu -> Tools -> Developer tools menu as shown below.

2. The Developer Tools window will be displayed;
3. Click the button that is shown below to inspect a corresponding element;
4. Click the element on the page;
5. A corresponding HTML element will be selected in the HTML window;
6. Determine the rule name as shown above;
7. Find this rule in the Style window as shown below:
Opera
Use the Opera Dragonfly tool.
1. Execute the Opera Dragonfly tool by pressing the Ctrl+Shift+I key combination on your keyboard. Alternatively, click the Menu -> Page -> Developer Tools -> Opera Dragonfly menu as shown below.
2. The Opera Dragonfly tool window will be displayed;
3. Check whether the following buttons are pressed as shown below:
4. Click the element on the page;
5. A corresponding HTML element will be selected in the HTML window;
6. Determine the rule name as shown above;
7. Find this rule in the Style window as shown below:
Safari

1. Click the Safari settings -> Preferences... menu as shown below.
2. In the Settings window click the Advanced tab and enable the Show Develop menu in menu bar option as shown below.
3. Close the Settings window and click the Menu for current page -> Develop -> Show Web Inspector menu.
The remaining steps are the same as for Google Chrome.


AspxComboxbox Client Side Events and Client Side Properties

1. How to get the Text of combobox in clientside javascript
===========================================================

Aspx Page Code
===============
<dx :ASPxComboBox ID="cmbExample1" ClientInstanceName="cmbExample" runat="server">
</dx: ASPxComboBox>

<asp:button Id="btnTest" Text="Show Text" OnClientClick="ShowComboText(); return false;" runat="server" >

Note: here "cmbExample" is the clientinstance name of the combobox control.

Javascript:
===========

function ShowComboText()
    var comboText= cmbExample.GetText(); 
  alert(comboText); 
}  

2. How to get the value of the combobox in clientside javascript
================================================================

 <asp:button Id="btnTest" Text="Show Value" OnClientClick="ShowComboValue(); return false;" runat="server" >

Note: here "cmbExample" is the clientinstance name of the combobox control.

Javascript:
===========

function ShowComboValue()
    var comboval= cmbExample.GetValue(); 
   alert(comboval);  
}  
                                    
3. How to find the item from combobox in clientside javascript
================================================================

 <asp:button Id="btnTest" Text="Show Item" OnClientClick="ShowFoundedItemByVal(); return false;" runat="server" >

Note: here "cmbExample" is the clientinstance name of the combobox control.

Javascript:
===========

function ShowFoundedItemByVal()
{  
    var comboitem= cmbExample.FindItemByValue('your value');
  alert(comboitem);  
}  

function ShowFoundedItemByText()
      var comboitem= cmbExample.FindItemByText('your value')
    alert(comboitem);   
}  
                                

4. How to remove from combobox in clientside javascript
================================================================

 <asp:button Id="btnTest" Text="Remove Item" OnClientClick="RemoveItem(); return false;" runat="server" >

Note: here "cmbExample" is the clientinstance name of the combobox control.

Javascript:
===========

function RemoveItem()
    var comboitem= cmbExample.FindItemByValue('your value')

 if (comboitem != undefined && comboitem != null
  {
         cmbExample.RemoveItem(comboitem.index);
          
   }
}  

Saturday, 31 August 2013

AspxGridView Client Side Events and Client Side Properties

1. How to check the column name exist in the aspxgridview client side
============================================
function GetColumn(s, e) 
{ 
      var MsgIDcolumn = s.GetColumnByField( "MsgID");           
       if (!!MsgIDcolumn) 
      {   
           return MsgIDcolumn;      
      }
}

2. How to get column values from the aspxgridview in client side
==========================================
function ShowValues(s, e) {
    s.GetRowValues(e.visibleIndex, 'ReletedWithChildId;ID',DisplayValues);
}

function DisplayValues(RelatedWithIDData)
{
    alert("ReletedWithChildId:" + RelatedWithIDData[0]);  alert("ID:" + RelatedWithIDData[1]);
}

How to Send Email from Python

Please find the below sample code to send email from Python. import os import smtplib from email.mime.multipart import MIMEMultipart...