Posts

Showing posts with the label SQL

.Net most asked interview questions for experienced professionals (C#,Asp WEBFORM,MVC,ASP CORE,WEB API,SQL Server,Java Script,Jquery)

Hello All Recently I have participated in multiple interviews. I found a lot of most frequently asked questions on the .Net framework. So I am just going to share with you, I hope it will be helpful while interview. I am just starting from C# questions and you have to find the answer over the Internet. I will update more question later C# Question    What is manage/Unmanaged code in c#  Tell me one scenario, Use of Interface instead of Abstract? Difference between Abstract Class and Interface with Scenario when to use it (Brief explain ) What happens if the inherited interfaces have conflicting method names? If one interface has 5 methods and wants to implement only 2 methods derived class. How can we do it? What Difference between Abstract and virtual method  and why we use if both near to  same  What is Constructor and its type, Default, Public, Private, Static  What is the Constructor Chaining in C#? What is...

check Record (Slot) is already exists between Start and End time in SQL Server

 In this  article I will show you how to  check Record is already exists between Start and End time . I have a table ,its having start and end time column with 3 rows(or it may be n of rows).so i am putting here my SQL query to get those records if any record  have time between Start and end time . DECLARE @mytable as Table (     StartTime time,     EndTime time ) INSERT INTO @mytable VALUES ('08:00', '08:30'), ('10:30', '12:30'), ('12:30', '14:15') DECLARE @StartTime time, @EndTime time SELECT  @StartTime = '14:15',         @EndTime = '18:15'   SELECT * FROM @mytable WHERE (     StartTime < @EndTime     AND EndTime > CASE WHEN @StartTime > @EndTime THEN '00:00' ELSE @StartTime END ) OR (     @StartTime > @EndTime     AND StartTime > EndTime ) OR (     @StartTime < @EndTime     AND StartTime > EndTime ...

Delete duplicate records from table in SQL Server using ROW_NUMBER()

Image
In this  article I will explain how to   Delete duplicate records from table in SQL Server using ROW_NUMBER(). sometimes we required to delete duplicate records from a table  . Suppose we have a table  with some duplicate data  GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Students]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL, [Class] [nchar](10) NULL,  CONSTRAINT [PK_tbl_Students] PRIMARY KEY CLUSTERED  ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO Now Create Query for delete and Excute it  WITH Tempstudents(Name,duplicateCount) AS ( SELECT Name,ROW_NUMBER() OVER(PARTITION by Name ORDER BY Name)  AS duplicateCount FROM tbl_Students ) DELETE FROM Tempstudents WHERE duplicateCount > 1  Snapshot After Excut...

how to check duplicate record before insert in asp.net

Image
In this  article I will explain how to  check duplicate record before insert in asp.net  using Stored Procedure  Step1 - Create table and Stored Procedure  GO /****** Object:  Table [dbo].[tbl_Login]    Script Date: 7/5/2016 10:56:06 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tbl_Login]( [Id] [int] IDENTITY(1,1) NOT NULL, [UserName] [nvarchar](50) NULL, [Password] [nvarchar](50) NULL,  CONSTRAINT [PK_tbl_Login] PRIMARY KEY CLUSTERED  ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO insert into tbl_Login (Username,Password)values('admin',123456) select * from tbl_Login CREATE PROCEDURE Insertintologin     @Username varchar(100),     @Password varchar(100)   AS BEGIN     SET NOCOUNT ON;     IF EXISTS(SEL...

Dynamic Mega Menu With Asp.Net with c#,java script and Sql Server.

Image
Introduction: In this article you’ll see how to Create dynamic  Mega Menu in asp.net .Having a menu and sub menus with links is very normal in a Web application. Typically, we create static menu and menu items. But sometimes we need dynamic mega menu when we do not know what the menu names and links will be called. Mega menus are a growing trend in web design . For sites that involve a lot of pages and/or products, a mega menu may be able to improve navigation and usability. Dynamic Mega Menu with ASP.NET, C#, jQuery and SQL Server solution that I would like to share with others puzzled with the same as was one of my website development i was having a tough time creating a Mega menu from database. Step1  Database:  I have 4 table category,subcategory  subcategory2 and  Brand  GO /****** Object:  Table [dbo].[tbl_Category]    Script Date: 07/30/2015 08:03:43 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...

how to Repeater update only when table rows updated in sql using SqlCacheDependency in ASP.Net?

Advantage -repeater/Gridview/Datalist do not load every time from database ,it load when any change or add in database . In this article, we are going to learn how to implement SQL Caching in ASP.NET using Poll based SQL Cache dependency SQL Cache dependency helps to cache tables in ASP.NET application in memory. So rather than making SQL server trips we can fetch the data from the cached object from ASP.NET. Step- 1 ALTER DATABASE MyDatabase SET ENABLE_BROKER Step- 2  aspx Page <asp:Repeater ID="RepDetails" runat="server">     <ItemTemplate>         <asp:Label ID="lblid" runat="server" Text='<%#Eval("Cat_Id") %>' Font-Bold="true"             Visible="false" />         <asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("Cat_Name") %>' ForeColor="Green"></asp:LinkButton>     </I...
Image
             Difference between INNER and OUTER joins In a database such as MSSQL, data is divided into a number of tables which are then connected (Joined) together by JOIN in SELECT commands to read records from multiple tables. Assuming you're joining on columns with no duplicates, which is a very common case: An inner join of A and B gives the result of A intersect B, i.e. the inner part of a venn diagram intersection. An outer join of A and B gives the results of A union B, i.e. the outer parts of a venn diagram union. Examples Suppose you have two Tables, with a single column each, and data as follows: A    B -    - 1    3 2    4 3    5 4    6 Note that (1,2) are unique to A, (3,4) are common, and (5,6) are unique to B. Inner join An inner join using either of the equivalent queries gives the intersection of the two tables, i.e. the tw...

How to format datetime & date in Sql Server 2008

Execute the following Microsoft SQL Server T-SQL datetime and date formatting scripts in Management Studio Query Editor to demonstrate the multitude of temporal data formats available in SQL Server. First we start with the conversion options available for sql datetime formats with century (YYYY or CCYY format). Subtracting 100 from the Style (format) number will transform dates without century (YY). For example Style 103 is with century, Style 3 is without century. The default Style values – Style 0 or 100, 9 or 109, 13 or 113, 20 or 120, and 21 or 121 – always return the century (yyyy) format. – Microsoft SQL Server T-SQL date and datetime formats – Date time formats – mssql datetime  – MSSQL getdate returns current system date and time in standard internal format SELECT   convert ( varchar ,   getdate (),  100 )   – mon dd yyyy hh:mmAM (or PM)                  ...