Tuesday, November 22, 2016

Simple SQL Queries to find duplicate record from table.

Here I am discussing about SQL Query to fetch the duplicate record from the database table.

Below query to fetch all record from the table:
SELECT * FROM Employee


Below query to fetch EmployeeName and No of Count that have same EmployeeName:
SELECT EmployeeName,Count(*) FROM Employee Group By EmployeeName

above query fetch all record including having count 1.



Below  query to fetch EmployeeName and No of Count that have same EmployeeName:

SELECT EmployeeName,COUNT(*) AS NoOfEmployee FROM Employee GROUP BY EmployeeName HAVING (COUNT(*)>1)

SELECT EmployeeName,COUNT(EmployeeName) AS NoOfEmployee FROM Employee GROUP BY EmployeeName HAVING (COUNT(EmployeeName)>1)

above query fetch all record including having count greater than 1.

Tuesday, November 15, 2016

Bulk Insert data into table without using loop.


Here i have comma separated string like '1,2,3,4', and i want to this value insert into table without using loop. To reduce the functionality of loop during bulk insertion i have used a table variable to insert the value in the table.

Here i am declaring Employee table:

Declare @Employee Table(EmployeeID int identity,EmployeeName nvarchar(50),Role int)

And also role table:
Declare @Role Table(RoleID int identity,Role int)

Now i am inserting role in Role Table:
Declare @ID nvarchar(50)='1,2,3,4,5'Declare @Role Table(RoleID int identity,Role int)
Insert Into @Role(Role)SELECT splitdata FROM fnSplitString(@ID,',')
Print 'Values in @Role'Select * From @Role

In Above i used a function 'fnSplitString' for split the commo separated data into the table.

Below you can see the value inserted into the Role table.



Now i am inserting role into the Employee Table using of Bulk Insertion as follows:

Insert Into @Employee(EmployeeName,Role) Select @EmployeeName,Role From @Role


Execute below all code :

Declare @ID nvarchar(50)='1,2,3,4,5'Declare @Role Table(RoleID int identity,Role int)
Insert Into @Role(Role)SELECT splitdata FROM fnSplitString(@ID,',')
--Print 'Values in @Role'--Select * From @Role

Declare @EmployeeName nvarchar(50)='Ajay Gangwar'Declare @Employee Table(EmployeeID int identity,EmployeeName nvarchar(50),Role int)
Insert Into @Employee(EmployeeName,Role) Select @EmployeeName,Role From @Role
Print 'Values in @Employee'Select * From @Employee

Below you can see the value inserted into the Employee table.



This is done functionality of bulk insertion without using loop.


Thursday, November 10, 2016

Unable to find control id on panel tab change.

Unable to find control id 'txtDOJ' referenced by the 'ControlToCompare' property of 'cvtxtEffectiveFrom'.

Description: An unhanded exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Unable to find control id 'txtDOJ' referenced by the 'ControlToCompare' property of 'cvtxtEffectiveFrom'.


Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


I am phasing this problem during accessing control id from Ajax TabContainer. Here I create multiple tab, and i want to access data from first tab to another tab. But this is throwing exception of "Unable to find control id."