We have to use the group by with having command to get the duplicate values. this query shall show the result of only the users have duplicate values in the employee table.
SELECT columnName FROM TableName
Group By columnName
Having Count(*)>1
Showing posts with label database. Show all posts
Showing posts with label database. Show all posts
How to get duplicate records from the Database
Posted by
Tushar Vaja
at
11:11 AM
,
Labels:
asp.net developer,
database,
duplicate records,
multiple records,
Sql Server
Fetch Multiple records from Database
Create Procedure [dbo].[Test]
@Flg1 bit,
@Flg2 bit,
@Flg3 bit,
AS
BEGIN
SET NOCOUNT ON;
Declare @Query varchar(max)
if(@Flg1<>0)
Begin
Set @Query='Select * from emplayee where empId=1'
End
if(@Flg2<>0)
Begin
Set @Query=@Query+'and empId=2'
End
if(@Flg3<>0)
Begin
Set @Query=@Query+'and empId=3'
End
Exec sp_executesql(@Query);
End
@Flg1 bit,
@Flg2 bit,
@Flg3 bit,
AS
BEGIN
SET NOCOUNT ON;
Declare @Query varchar(max)
if(@Flg1<>0)
Begin
Set @Query='Select * from emplayee where empId=1'
End
if(@Flg2<>0)
Begin
Set @Query=@Query+'and empId=2'
End
if(@Flg3<>0)
Begin
Set @Query=@Query+'and empId=3'
End
Exec sp_executesql(@Query);
End
Subscribe to:
Posts (Atom)