Translate

Tuesday, 25 July 2017

sql: RIGHT and LEFT


sql query
select RIGHT(value,noofCharater);
select LEFT(value,noofCharater);


select RIGHT('pabitra',2)-- result ra
select LEFT('pabitra',2)--result pa

RIGHT: It extract right value from given no.
RIGHT: It extract left value from given no.

Friday, 21 July 2017

sql : query for total no of column in a table

SELECT count(*)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'tblEmployee'


or

SELECT COUNT(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'master' AND TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'tblEmployee'

Friday, 14 July 2017

prevent browser back button in any browser


<script type = "text/javascript" >
        function preventBackButton() {
            window.history.forward();
        }
        setTimeout("preventBackButton()", 0);
        window.onunload = function () { null };
</script>






CurrentPage
----------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrentPage.aspx.cs" Inherits="CurrentPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type = "text/javascript" >
        function preventBackButton() {
            window.history.forward();
        }
        setTimeout("preventBackButton()", 0);
        window.onunload = function () { null };
</script>
</head>

<body>
    <form id="form1" runat="server">
    <div>
    <a href="NewPage.aspx">New Page</a>
 
    </div>
    </form>
</body>
</html>




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

NewPage

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

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewPage.aspx.cs" Inherits="NewPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <script type = "text/javascript" >
          function preventBackButton() 
          {
              window.history.forward(); 
           }
           setTimeout("preventBackButton()", 0);
          window.onunload = function () { null };
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    
    <a href="CurrentPage.aspx">CurrentPage</a>
    </div>
    </form>
</body>
</html>


Wednesday, 28 June 2017

sql :Assign comma in sql column , sql xml path


Syntax
STUFF(string, start, length, new_string)



SELECT STUFF('01234567', 'ketenumber position', 'keteta', 'replace value');
SELECT STUFF('01234567', 4, 2, ''); ---result 012567
ie 34 is gone
3 is at 4 position




select ','+ Roll_No from Candidate where Dist_code='02' for XML path('')

result : ,1,2,3,4,5,6,7



select stuff(
(
    select ','+ Roll_No from Candidate where Dist_code='02' for XML path('')
),1,1,'')


result : 1,2,3,4,5,6,7






Tuesday, 20 June 2017

sql: restore sql database using sql query

--Step: 1
---------
--Get the FILELISTONLY of backup file in disk location
    RESTORE FILELISTONLY
    FROM DISK ='E:\Pabitra\dbSample.BAK'
    -- Find the "LogicalName" column MDFLogicalName and LDFLogicalName which is use inthe next query
    --My MDFLogicalName is dbSample and LDFLogicalName is dbSample_log
    -- then Run the below code
--Step : 2
---------
RESTORE DATABASE dbNewName
FROM DISK ='E:\Pabitra\dbSample.BAK'
WITH MOVE 'dbSample' TO 'E:\Pabitra\dbNewName.mdf',
MOVE 'dbSample_log' TO 'E:\Pabitra\dbNewName.ldf'