I wonder how to build the logic for the scenario below (I am using SQL Server 2008 and above).
In TblMaster, each entry will have a Start and End value. Along with this is the CharToAdd varchar column. If the range says 1 to 3, then TblDetails should have an entry for 1,2,3. Not sure if I am explaining this effectively, so I provided a screenshot with an example of I / O.
Ranges will range from 5,000 to 100,000 (max), so performance is also a concern.
Table:
CREATE TABLE [dbo].[VMaster](
[VID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
[VName] [varchar](30) NOT NULL
)
GO
CREATE TABLE [dbo].[TblMaster](
[SID] [int] IDENTITY(1,1) NOT NULL Primary Key,
[VID] [int] NOT NULL,
[CreatedDate] [datetime] default (getdate()) NOT NULL,
[CharToAdd] [varchar](10) NOT NULL,
[Start] [int] NOT NULL,
[End] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TblDetails](
[DetailsID] [int] IDENTITY(1,1) NOT NULL Primary Key,
[SID] [int] NOT NULL,
[Sno] [int] NOT NULL,
[ConcatenatedText] [varchar](20) NOT NULL,
[isIssued] [bit] default (0) NOT NULL,
[isUsed] [bit] default (0) NOT NULL
)
GO
ALTER TABLE [dbo].[TblMaster] WITH CHECK ADD CONSTRAINT [fk_SI_id] FOREIGN KEY([VID])
REFERENCES [dbo].[VMaster] ([VID])
GO
ALTER TABLE [dbo].[TblMaster] CHECK CONSTRAINT [fk_SI_id]
GO
Example data for tables:
Insert into dbo.VMaster Values ('A1')
GO
Insert into dbo.TblMaster Values (1,default, 'ABC', 100, 105)
GO
Examples of records inserted into tables and the result expected in TblDetails:

EDIT: , TblMaster ? TblDetails 0 , " ".
Update dbo.TblMaster
Set Start = 101, [End] = 103
Where SID = 1
Update dbo.TblMaster
Set Start = 1000, [End] = 1500
Where SID = 1