Insert Query in Linq to SQL

SQL Server BETWEEN operator

The BETWEEN operator is used to select the values within a range.

Syntax:
-- Used of BETWEEN 
SELECT col1, col1
   FROM Table_name
WHERE col1 BETWEEN val1 AND val2;
-- CREATE TABLE
CREATE TABLE [dbo].[Tbl_Demo](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](500) NULL,
    [Age] [int] NULL,
    [IsActive] [bit] NULL,
    [IsDeleted] [bit] NULL,
 CONSTRAINT [PK_Tbl_Demo] 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
SET ANSI_PADDING OFF
GO
--INSERT TABLE ROWS
SET IDENTITY_INSERT [dbo].[Tbl_Demo] ON 

GO
INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES (1, N'Anil Singh', 30, 1, 0)
GO
INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES (2, N'Aradhya', 3, 1, 0)
GO
INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES (3, N'Reena', 28, 1, 0)
GO
INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES (4, N'Sunil Singh', 27, 1, 0)
GO
INSERT [dbo].[Tbl_Demo] ([ID], [Name], [Age], [IsActive], [IsDeleted]) VALUES (5, N'Sushil', 22, 1, 0)
GO
SET IDENTITY_INSERT [dbo].[Tbl_Demo] OFF
GO

-- RESULT LOOKS LIKE
SELECT * FROM [dbo].[Tbl_Demo] 
    WHERE ID BETWEEN 1 AND 3

ID  Name    Age IsActive    IsDeleted
---------------------------------------------------
1   Anil Singh  30  1   0
2   Aradhya 3   1   0
3   Reena   28  1   0

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^