Posts

Showing posts from 2013

Delete duplicate records using this script in MS Sql Server

Hi Friends , You can delete duplicate records using this script in MS Sql Server. I write a example below. Declare @tblEmployee As table  ( Eid int, Ename varchar(10) )   insert into @tblEmployee values(1,'A') insert into @tblEmployee values(2,'B') insert into @tblEmployee values(3,'A') insert into @tblEmployee values(4,'D') insert into @tblEmployee values(5,'B') Select * from @tblEmployee  Delete From @tblEmployee Where Eid in ( Select Eid from  (Select * , ROW_NUMBER() Over ( partition by Ename Order by Ename ) As ICount  From @tblEmployee )As Qry Where Qry.ICount > 1 ) Select * from @tblEmployee 

Windows Service Install and Un Install in MS VisualStudio 2010

Hi Friends, You can learn How to Install and Un Install Windows Service using Microsoft Technology. >> 1 .First get the path where InstallUtil.exe exist its Mostly the path is same but differ version  it can be differ C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe >> 2 .Get the Path where you want to put that Service .exe file (Assume it is on "E:\MyApp\MyTestApp.exe") >> 3 .Command for Install service Run Visual Studio Command Prompt as Run admin if Windows 8 else no need to it and Type this C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe E:\MyApp\MyTestApp.exe -i >> 4 .Command for Un Install service Run Visual Studio Command Prompt as Run admin if Windows 8 else no need to it and Type this C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe E:\MyApp\MyTestApp.exe -u >> 5 .In case if you already installed Service and you can see there "services.msc" Service list and you have

Find Store Procedures and Functions in MS SQL Server.

Hi Friends , This article will help you to find Store Procedures and Functions in Microsoft SQL Server. Execute this Script which i mentioned below. ROUTINE_TYPE =  'PROCEDURE' OR    'Function' Select  ROUTINE_TYPE , SPECIFIC_NAME , ROU TINE_DEFINITION FROM     INFORMATION_SCHEMA.ROUTINES WHERE    OBJECTPROPERTY ( OBJECT_ID ( SPECI FIC_NAME ), 'IsMSShipped' )   = 0         AND  ROUTINE_DEFINITION   like   '%PrcName%'         AND  ROUTINE_TYPE = 'PROCEDURE'

Draw Line and Text on Bitmap Image in C#

Hello Friends ,  This is a sample Class example of C#,using this code you can Draw the text and line using Graphics pen on Bitmap images. Sample example code (C# Language - VS.Net) ---------------------------------------------------------------------------------------------------------- using System; using System.Drawing; using System.IO; using System.Diagnostics; using System.Data; using System.Drawing.Imaging; using System.Threading; using System.Collections; using System.Globalization; using System.Windows.Forms; using System.Configuration; using System.Net; using System.Net.Mail; using System.Net.NetworkInformation; namespace MyTest { public class GenerateImage { private Thread [] threads; private System.Collections. Hashtable hashConnectionInfo = new System.Collections. Hashtable (); public string appPath = "E:\\MyPenImage\\" ; public GenerateImage()

Recursive CTE in SQL SERVER

Step1. Create Table CREATE TABLE [dbo].[RegMast]( [RegID] [int] NOT NULL, [RegNo] [varchar](12) NULL, [RegName] [varchar](50) NULL, [UplineRegID] [int] NULL, [UplineLeg] [varchar](1) NULL, [SponsorRegID] [int] NULL, [IsActive] [bit] NULL, [FirstName] [varchar](50) NULL, [MIddleName] [varchar](50) NULL, [LastName] [varchar](50) NULL, [Password] [nchar](10) NULL, [DateofJoin] [datetime] NULL, [DateofBirth] [datetime] NULL, [Occupation] [varchar](50) NULL, [Qualification] [varchar](50) NULL, [EmailID] [varchar](15) NULL, [ContactNo] [varchar](10) NULL, [Photo] [varchar](50) NULL, [IsDelete] [bit] NULL, [IsCreatedOn] [datetime] NULL, [IsUpdatedOn] [datetime] NULL, [IsDeletedOn] [datetime] NULL,  CONSTRAINT [PK_RegMast] PRIMARY KEY CLUSTERED  ( [RegID] ASC )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] ) ON [PRIMARY] Step 2. Declare @RegI

Delete duplicate records in SQL Server

Declare @tbl As table  ( iid int, iname varchar(10) )   insert into @tbl values(1,'A') insert into @tbl values(2,'B') insert into @tbl values(3,'C') insert into @tbl values(4,'A') insert into @tbl values(5,'C') Select * from @tbl  Delete From @tbl Where iid in ( Select iid from  (Select * , ROW_NUMBER() Over ( partition by iname Order by iname ) As ICount  From @tbl) As Qry Where Qry.ICount > 1 ) Select * from @tbl

Repair Suspect Database using Query In SQL Server

This is the query to repair suspect database in SQL Server.   If your Database is marked as suspected, here are the steps to fix it.       In this you have replace “dbName” with suspected db name and run this query in master database. Step 1 --command to recover suspected database ALTER DATABASE DbName SET EMERGENCY DBCC checkdb('DbName') ALTER DATABASE DbName SET SINGLE_USER WITH ROLLBACK IMMEDIATE DBCC CheckDB ('DbName', REPAIR_ALLOW_DATA_LOSS) ALTER DATABASE DbName SET MULTI_USER          This step 1 cannot set Index created for that database so now we have to rebuild the index. This query should be run in that suspected database. Step 2 -- command to rebuild all indexes EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', 80)"

Create Folder / Directory using SQL Server

Dear Friends we can use command of command prompt in sqlserver   use   xp_cmdshell   for fire batching command   Like   EXEC   xp_cmdshell   ' Command String ' EXEC xp_cmdshell 'dir *.exe'   to get all directory information EXEC xp_cmdshell 'mkdir kunal' to Create New Directory is deafult path system32 you can set Reference From : http://www.c-sharpcorner.com/Blogs/9569/create-directory-using-sqlserver.aspx 

Get Column values in a single coma separated string in SQL Server

Image
We can get all values of a column in a single coma separated string this query.  Declare @id  varchar(Max) Select @id = coalesce(@id + ',' ,'') + Cast(ItCode as varchar(10)) From ItMast Select @id  After you will get result like this Reference From : http://www.c-sharpcorner.com/Blogs/9637/get-a-column-value-in-a-single-coma-separated-string-in-sql.aspx

Get Nth Highest Value by SQL Query

CREATE   TABLE   [dbo] . [tblDupRecord] (       [id] [int]   NULL,       [name] [varchar] ( 50 )   COLLATE   SQL_Latin1_General_CP1_CI_AS   NULL,       [marks] [int]   NULL )   ON   [PRIMARY] GO insert   into   [tblDupRecord]   values ( 1 , 'Name1' , 25 ) insert   into   [tblDupRecord]   values ( 2 , 'Name2' , 50 ) insert   into   [tblDupRecord]   values ( 3 , 'Name3' , 35 ) insert   into   [tblDupRecord]   values ( 4 , 'Name4' , 40 ) insert   into   [tblDupRecord]   values ( 5 , 'Name5' , 45 ) insert   into   [tblDupRecord]   values ( 6 , 'Name6' , 45 ) GO   select   *   from   tblDupRecord  a where   2 =   ( select   count (   distinct ( b . marks ))   from   tblDupRecord b   where   a . marks   <= b . marks )   Go   select   top   1   with   ties   *   from   ( select   top   2   with   ties   *     from   tblDupRecord   order   by   marks   desc )   as   t   order   by marks   asc GO   with

Get comma Separated Data using XML Path

Select    Qry .*,   Case   When   Qry . Door   =   ''   Then   Qry . Door   Else     Substring ( Qry . Door ,   3 , Len ( Qry . Door )   -   2 )   End   As   Door From     ( SELECT   dbo . tblHardware . Cmp_Id ,   Hardware_Id   ,   Hardware_Code   AS   [Hardware Code] , ( Select   ', '   +   cast ( Door_Name   as   varchar )   FROM   tbldoor                            WHERE   tbldoor . Hardware_Id   = tblHardware . Hardware_Id   FOR   XML   path ( '' ))   Door FROM   dbo . tblHardware   WHERE   ( dbo . tblHardware . Is_Deleted   =   0 ) )   As   Qry    Reference By http://www.c-sharpcorner.com/Blogs/10297/fetch-comma-separated-data-using-xml-path.aspx