Solved

sql server stored procedure - lookups & variables

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Whats wrong in this query - Select * from tableA,tableA 11 45
Syntax Issue with SSIS module 26 103
Help with Oracle IF statment 5 24
shrink table after huge delete 2 13
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 …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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