[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Lookup Values

Posted on 1998-10-07
1
Medium Priority
?
202 Views
Last Modified: 2010-03-19
Does anyone know of a third-party-product that will allow a MS SQL 7 field to check another table to determine valid values?  This can't be done with a foreign key in my scenario and I don't believe it can be done in SQL.
0
Comment
Question by:scarlett
1 Comment
 
LVL 2

Accepted Solution

by:
formula earned 100 total points
ID: 1090447
Hi Scarlett!

To do what you want to do, you need to write a trigger.
A trigger will valid values in an insert or update from a lookup table.  It will be something like this:

create trigger validate_field
on data_table
for insert,update
as

if (select count(*) from data_table, inserted
       where lookup_table.field!=inserted.field) > 0
 begin
   rollback trans
   raiserror('Error inserting records, Value not valid,16,101)
 end
return
GO

This is not exact, but the general idea.  Let me know if you need any further assistance.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question