Wednesday 27 March 2013

Parsename to Extract Precision and Scale values‏ From Decimal Numbers


   
The numeric datatype stores numbers with precision and scale. Suppose you want to extract only a precision or a scale, you can do it via many ways. One of the ways is to make use of the PARSENAME function.

Consider the following example

declare @amount decimal(12,2)
set @amount=87234.50
select parsename(@amount,2) as precision, parsename(@amount,1) as scale

The result is

precision            scale
---------            --------
87234                  50

Parsename is used to extract specified part of a name. In general, it is used to extract names from four part object names separated by a dot. Argument number 1 extracts the last part of a string, and the 2nd argument extracts the next last part.

This way we can effectively make use of parsename function to extract precision and scale values from the decimal numbers.

TOP 5 costly Stored Procedures in a SQL Server Database

Execute this query on corresponding Database

SELECT TOP 5 obj.name, max_logical_reads,
 max_elapsed_time
FROM sys.dm_exec_query_stats a
CROSS APPLY sys.dm_exec_sql_text(sql_handle) hnd
INNER JOIN sys.sysobjects obj on hnd.objectid = obj.id
ORDER BY  max_logical_reads  DESC

Combine Multiple Rows into One Row using SQL Server


   
Imagine you have a column like this:

Numbers
---------
One
Two
Three
Four
Five

The output you desire is to combine all the rows and put it as one row similar to the following:

OneTwoThreeFourFive


Let us see how to do it:

-- Sample Script to create the table and insert rows
-- By SQLServerCurry.com

CREATE TABLE #Temp
(
[Numbers] varchar(40)
)
INSERT INTO #Temp VALUES('One');
INSERT INTO #Temp VALUES('Two');
INSERT INTO #Temp VALUES('Three');
INSERT INTO #Temp VALUES('Four');
INSERT INTO #Temp VALUES('Five');


-- Query to combine multiple rows into one

DECLARE @str VARCHAR(100)
SELECT @str = COALESCE(@str + '', '') + [Numbers]
FROM #Temp
Print @str

Monday 25 March 2013

TO disable right click on any web page or image

In the body tag write property name oncontextmenu="return false"
this will stop right click on web page..

same thing write on img tag to disable right click ..

Saturday 2 March 2013

Add favicon in address bar

Place this code in head section of HTML section

<html>
  <head>
   <link runat="server" rel="shortcut icon" 
    href="~/favicon.ico" type="image/x-icon" />
    <link runat="server" rel="icon"  
    href="~/favicon.ico" type="image/ico" />
</head>
<body>
</body>
</html>
 
 
and here is web site that will convert any pic to icon
 
http://www.html-kit.com/favicon/  

Total Pageviews