Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Unique Order # with Order # + Sequence #

Status
Not open for further replies.

mwake

Programmer
Feb 12, 2004
151
US
I have an order table and lab results table. The field I am joining the tables on is OrderID, but it's not unique because if the patient is given multiple tests, each test has the same OrderID. I need to update some tests but not all of them, so I need to get to the test level to evaluate each record. I want to create a new OrderId by using the existing OrderID(ex. PRO12345) and adding a sequence number at the end(ex. PRO12345-1, PRO12345-2, etc) for each test. Then I want to add this new OrderID to my order and lab result tables to use as a join for my update. How do I do this??
 
CREATE TABLE OrderLabBridgeTable (
OrderLabBridgeKey integer,
OrderID it's type and size,
OrderSeq integer,
LabResultsID it's type and size);

Then write a TRANSACT-SQL cursor to populate the table. I'll add an example later. Then write a trigger to keep the bridge table in sync.


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Thanks John. Please add the example of the cursor to populate the table. I'm handle reporting but I'm not a SQL wizard. I usually work with DBA's to handle things like this. I appreciate the suggestion...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top