Category: SQL Server
Cube and Rollup Operator in SQL Server 2008
CUBE operator is used with Group by clause. It use to get the subtotal and grand total…
Insert multiple rows into a table from another table and get identity values
Let me explain the case first, so you will get the idea when this is required to…
SQL Server Transaction
BEGIN TRANSACTION BEGIN TRY — put SQL commands here INSERT/UPDATE/Delete — if successful – COMMIT the work…
MSSQL Selecting top 10 but include columns with duplicate values
SAMPLE RECORDS Query for getting top 10 records based on the company values with duplicate values select…
Attendance UNPIVOT first then Pivot for count present, absent etc in SQL
Sample data download: here Declare @tempAttendance table(EmpID int, EmpName varchar(50), edate int, ecode varchar(5)) insert into @tempAttendance…
Dynamically create columns in a temp table and generate pivot report
Sample Data download: http://goo.gl/lcOf8z Generate excel report as below. Username, Address, City, State, Zip, Question 1, Question…
function for spliting a string and return a table in SQL Server
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[unqSplit](@String nvarchar(4000), @Delimiter char(1)) RETURNS @Results TABLE…
How to schedule and automate backups of SQL Server databases in SQL Server Express
Create store procedure. // Copyright © Microsoft Corporation. All Rights Reserved. // This code released under the…
How to compare two tables of different database – SQL Server
To find records which exist in source table but not in target table: SELECT * FROM t1…
User Dynamic query for search records and use uniqueidentifier
Declare @SearchText nvarchar(max) set @SearchText = ‘sah.CheckInCheckOutDateTime>=”2011-09-28 10:00:00.000”’ Declare @SchoolYearId uniqueidentifier set @SchoolYearId=’25511F7F-8F87-4085-A242-2004F4419D36′ Declare @Str as nvarchar(max)…