Tuesday, December 24, 2013

C#: Get Hours, Minutes, seconds from total Minutes using TimeSpan

var ts = TimeSpan.FromMinutes(intMinutes);
var message = string.Format("Hours: {0}, Minutes: {1}, Seconds: {2}", ts.Hours, ts.Minutes, ts.Seconds);

Console.WriteLine(message);

Copy a table into new table with/without data conditionally / unconditionally - SQL Server

1. Copy only the structure of an existing table into new table:

SELECT * INTO [DBName]. dbo.tblNonExistingTable FROM [DBName].dbo.tblExistingTable WHERE 1=2

The above query will copy the structure of  an existing table(tblExistingTable ) into the new table(tblNonExistingTable).


2. Copy the structure plus all the data of an existing table into new table:

SELECT * INTO [DBName]. dbo.tblNonExistingTable FROM [DBName].dbo.tblExistingTable

The above query will copy the structure of  an existing table(tblExistingTable ) into the new table(tblNonExistingTable) as well as data.


3.  Copy only the data of an existing table into an existing table in other DB:
INSERT INTO [DBName]. dbo.tblDestExistingTable
SELECT * FROM [DBName].dbo.tblSourceExistingTable

The above query will copy all the data of  an source table(tblSourceExistingTable) into the another DB table(tblDestExistingTable).

4.  Copy only the data of an existing table into an existing table in other DB on the basis of some condition:
 INSERT INTO [DBName]. dbo.tblDestExistingTable
SELECT * FROM [DBName].dbo.tblSourceExistingTable Where id > 50

The above query will copy the data of  an source table(tblSourceExistingTable) into the another DB table(tblDestExistingTable) having id of source table(tblSourceExistingTable) greater than 50. So, Lets say, there are 100 records in source table from id 1 to 100, then it will copy only 50 records to destination table.




Tuesday, December 3, 2013

Calculate the dates of previous, current and next month

--SQL Server 2005/2008/2012
DECLARE @DATE DATETIME
 
Select @DATE = GetDate()
 
--First date of the Previous Month
SELECT CONVERT(VARCHAR(10),DATEADD(MONTH, DATEDIFF(MONTH,0,@DATE)-1,0),120) AS [Previous Month]
 
--First date of the Current Month
SELECT CONVERT(VARCHAR(10),DATEADD(MONTH, DATEDIFF(MONTH,0,@DATE),0),120) AS [Current Month]
 
--First date of the Next Month
SELECT CONVERT(VARCHAR(10),DATEADD(MONTH, DATEDIFF(MONTH,0,@DATE)+1,0),120) AS [Next Month]
 
Previous Month
--------------
2013-11-01
 
(1 row(s) affected)
 
Current Month
-------------
2013-12-01
 
(1 row(s) affected)
 
Next Month
----------
2014-01-01
 
(1 row(s) affected)

Thursday, November 21, 2013

Get the records Count of RADGRID using Jquery


<script type="text/javascript">
function RowCount()
{
    var grid = $find("<%=RadGrid1.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var Rows = MasterTable.get_dataItems();
    alert(Rows.length);
}
</script>

Show selected div on radiobutton list selection using Jquery

<label><input id="rdb1" type="radio" name="toggler" value="1" />Money</label>
<label><input id="rdb2" type="radio" name="toggler" value="2" />Interest</label>

<div id="blk-1" class="toHide" style="display:none">
    First Div
</div>
<div id="blk-2" class="toHide" style="display:none">
    Second Div
</div>

$(function() {
    $("[name=toggler]").click(function(){
            $('.toHide').hide();
            $("#blk-"+$(this).val()).show('slow');
    });
 });

Friday, November 8, 2013

Default location for storing the .SqlLite DB file on MAC

Default Location:
~/Library/Application Support/iPhone Simulator/[SDK version]/Applications/[App GUID]/Documents

To find the path at Finder (Hint):
Right Click on Finder -> Select Go to Folder -> Enter the following 
~/Library/Application Support/iPhone Simulator/




Monday, October 21, 2013

Regular Expression for Email

var regEmail = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";