
DECLARE @TeleHealthVendorMeasurementThresholdRanges TABLE (
	[VendorId] [int] NULL,
	[FieldCode] [nvarchar](500) NOT NULL,
	[MeasurmentUnit] [nvarchar](500) NOT NULL,
	[MinThreshold] [float] NULL,
	[MaxThreshold] [float] NULL
)

INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'SystolicBloodPressure','kPa',9.3,26.7	from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'SystolicBloodPressure','MmHg',70,200	from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'DiastolicBloodPressure','kPa',6.6,17.4	from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'DiastolicBloodPressure','MmHg',50,130	from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'PulseRate','Bpm',30,250					from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'OxygenSaturation','Percent',70,100		from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'BodyTemperature','Celsius',30,43		from vendortbl 
INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) select vendorid,'BodyTemperature','Fahrenheit',86,109.4	from vendortbl 
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'GlucoseLevel','MgDL',,)
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'GlucoseLevel','MmolL',,)
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'Height','Cm',,)
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'Height','Feet',,)
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'Weight','Kgs',,)
--INSERT INTO @TeleHealthVendorMeasurementThresholdRanges(vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold) VALUES(2,'Weight','Lbs',,)



MERGE INTO TeleHealthVendorMeasurementThresholdRanges AS TARGET  
USING @TeleHealthVendorMeasurementThresholdRanges AS SOURCE  
ON target.vendorid=source.vendorid
	and target.fieldCode=source.fieldCode
	and target.[MeasurmentUnit]=source.[MeasurmentUnit]
WHEN NOT MATCHED BY TARGET THEN
INSERT (vendorid,fieldCode,[MeasurmentUnit],minthreshold,maxthreshold)
VALUES (SOURCE.vendorid,SOURCE.fieldCode,SOURCE.[MeasurmentUnit],SOURCE.minthreshold,SOURCE.maxthreshold)
;