Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

sql server stored procedure - lookups & variables

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
vbnetcoder
Asked:
vbnetcoder
  • 2
  • 2
1 Solution
 
wdosanjosCommented:
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
 
vbnetcoderAuthor Commented:
OR should I do all the lookups before I do the select?
0
 
wdosanjosCommented:
Combining the lookups in the same select will give you a better performance, as the database will optimize the query for you.
0
 
vbnetcoderAuthor Commented:
ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now