Solved

sql server stored procedure - lookups & variables

Posted on 2011-09-06
4
203 Views
Last Modified: 2012-08-13
I need to create a stored procedure in the following format:
INSERT INTO dbo.Table(
       Row1,
      Row2,
      Row3,
etc


Select Row1,
      Row2,
      Row3,
etc

FROM SomeTable

--- But ---

Row1 for example might require a lookup from another database table.
How would I do the lookup so that the returned value could be inserted
into the table?
0
Comment
Question by:vbnetcoder
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
Comment Utility
It would be something like this:

INSERT INTO dbo.Table(
       Row1,
      Row2,
      Row3,
etc


Select (Select Lookup From OtherTable Where LookupColumn = Row1),
      Row2,
      Row3,
etc

FROM SomeTable

Open in new window


I hope this helps.
0
 

Author Comment

by:vbnetcoder
Comment Utility
OR should I do all the lookups before I do the select?
0
 
LVL 23

Expert Comment

by:wdosanjos
Comment Utility
Combining the lookups in the same select will give you a better performance, as the database will optimize the query for you.
0
 

Author Closing Comment

by:vbnetcoder
Comment Utility
ty
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now