Solved

sql server stored procedure - lookups & variables

Posted on 2011-09-06
4
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 36491507
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
ID: 36491519
OR should I do all the lookups before I do the select?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 36491552
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
ID: 36495923
ty
0

Featured Post

Industry Leaders: 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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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