Showing posts with label asp.net developer. Show all posts
Showing posts with label asp.net developer. Show all posts

How to get duplicate records from the Database

,
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

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