I have a table like this:
Create table landingzone.classes(
teacher nvarchar(255)
,moment nvarchar(255)
,noOfStudents nvarchar(255)
,scheduledYesNo nvarchar(255)
)
INSERT INTO [landingzone].[classes]
([teacher]
,[moment]
,[noOfStudents]
,[scheduledYesNo])
Select ' Henrov', ' 01/07/2021' ,6 ,'True'
union all
Select ' Bill', ' 01/05/2021' ,6 ,'False'
union all
Select ' Henrov', ' 31/07/2021' ,NULL ,NULL
What I need is a script that finds out that
[teacher]
should be anvarchar(255)
[moment]
should be atimestamp
[noOfStudents]
should be anint
[ScheduledYesNo]
should be anbit
(or anint
with 1/0 as value)
and creates a table like this:
Create table staging.classes(
teacher nvarchar(255)
,moment datetime
,noOfStudents int
,scheduledYesNo bit
)
followed by a datatransfer from landingzone.classes
to staging.classes
.
However, it should do this by analyzing the table dbo.test, not by referring to some config tables containing the names of the columns with associated datatype. Due to the possible large numbers of records in dbo.test where a lot of fields can be empty, it should look past the first 200 (preferably this number should be configurable)
The tables in the landingzone are delivered by other processes and should explicitly keep existing in the current form (business rule).
The challenge I think is mostly in autodiscovering the proper datatypes.
Can this be done in BIML?