I wish to go down all the rows of a table and, from a single column, take the values one by one and check if this value is found between two values from two additional columns in another table. If it is, I wish to assign the value 1 to the column of a third table that has a row occurring for each of the initial values. The value that I am initially extracting can be sorted. The between range values are situated in the second table and can overlap.
In other words
(using tables from which I have removed some collumns),
I wish to take values from table 1:
Table 1:
Look for these values in table 2:CREATE TABLE ICD_9 ( ICD_9 VARCHAR(10) NOT NULL, /*Unique values taken from here*/ + )
/* This table needs to be built from the previous two */CREATE TABLE ICD_specifications_for_disease ( + Range_key int NOT NULL, Disease_or_health_catagory VARCHAR(30) NOT NULL, ICD_catagory int NOT NULL, ICD_start VARCHAR(5) NULL, /*between this value and */ ICD_end VARCHAR(5) NULL, /* and this value */ + Date_created TIMESTAMP +NOT NULL, PRIMARY KEY (Range_Key) )
CREATE TABLE ICD_9_Disease_Types ( ICD_9_code VARCHAR(4) NOT NULL, /* same as first collumn in +table 1*/ CHD int DEFAULT '0' NOT NULL, Circulatory_Disease int DEFAULT '0' NOT NULL, All_Cancer int DEFAULT '0' NOT NULL, Lung_Cancer int DEFAULT '0' NOT NULL, Breast_Cancer int DEFAULT '0' NOT NULL, Cervical_Cancer int DEFAULT '0' NOT NULL, Colorectal_Cancer int DEFAULT '0' NOT NULL, Skin_Cancer int DEFAULT '0' NOT NULL, Respiratory_Disease int DEFAULT '0' NOT NULL, COPD int DEFAULT '0' NOT NULL, Stroke int DEFAULT '0' NOT NULL )
I am using MS SQL Server. Does anyone kindly have any tips or code?
20031201 Edit by BazB: Changed title from 'Creating tables from others'
In reply to OT: Creating tables from others by Win
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |