Solved

sql server stored procedure - lookups & variables

Posted on 2011-09-06
4
205 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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