Database

Different way to find 2nd minimum Salary TIP #36

  Mostly people faced this question in interview find highest salary so I am just trying to explain different ways let us understand this by following example suppose we have following table of employees with salary Query 1:-  by  aggregate function SELECT MAX (fltBasicSalary)FROM @tblEmployeeSalaryWHERE fltBasicSalary IN (SELECT DISTINCT TOP 2 fltBasicSalaryFROM @tblEmployeeSalaryORDER BY fltBasicSalary …

Row_Number() function for providing sequence number as per your wish TIP #35

  Sometimes we require sequence column or we can a row number column so we have ROW_NUMBER() function in SQL SERVER. Lets understand this by following example In this example we have  person table which have firstname, last name, middlename  columns. Now we want to fetch records  with a extra column ROW_Number() so we write …

Get different records or random order at each time when you fetch record by newId() TIP#33

Hello friends, Sometimes your project require whenever a page load or user search then each time you need to show a random order or we can say different records or order. To achieve this we can use following command SELECT * FROM yourtableName order by NewID() in below snap I am fetching person table of …

Easy way to find result set of a stored procedure without running it- TIP #32

  Sometimes , We need to know what is the structure of stored procedure ? , How many columns will be return ? So to determine this we have easy stored procedure provided by SQL Server which is sp_describe_First_Result_Set. Below is the template to run it. You can provide your stored procedure name as variable …

Performance tips :- Different reports to analyze your SQL Server who is making it slow. TIP#31

Dear Friends, One of the really important part of any database is performance. Everyone complaining your system is slow , your database performance is slow but why it is slow ? Most of the time we are not aware what is the source?  Which SQL statement creating problem? Lets understand this thing why our SQL …

PARSENAME function TIP#29

As the name suggested PARSENAME is the SQL Server function which provide help in parsing. Lets understand this by an example Suppose , I have an IPAddress variable which I need to parse DECLARE @IPAddress AS VARCHAR(100)SET @IPAddress=’412.312.800.713′ SELECT PARSENAME (@IPAddress,1) The syntax of the parsename is simple PARSENAME(String,stringPartIndex) Only few things which  I have …