Dear Monks,

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:

CREATE TABLE ICD_9 ( ICD_9 VARCHAR(10) NOT NULL, /*Unique values taken from here*/ + )
Look for these values in table 2:
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) )
/* This table needs to be built from the previous two */
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.