Solved

SQL Loop help (temp tables etc)

Posted on 2013-01-17
3
202 Views
Last Modified: 2013-01-18
I have a main table and a small lookup table.

Im trying to get the ids from my streets table to my benchmarks table.

So in streets I have 2 columns.

Id
Streetname

In Benchmarks I have a streetid field that I want to contain the value of the Id column in streets table.  I need to use Streets.Streetname and Benchmarks.Street1 as the where.

So in psuedo code:  
update dbo.benchmarks set dbo.benchmkarks.street1id = dbo.streets.id where dbo.benchmarks.street1id = dbo.streets.streetname.

Obviously this will take a loop to read in all the rows in streets and then do the processing unfortunately ive never grasped fully how to get this right in sql.

Thanks in advance and please view the attachment that shows my columns.

my db schema
0
Comment
Question by:rochestermn
[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
3 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38789749
update dbo.benchmarks
set dbo.benchmkarks.street1id = dbo.streets.id
FROM dbo.streets
where dbo.benchmarks.street1id = dbo.streets.streetname.
0
 
LVL 39

Accepted Solution

by:
appari earned 500 total points
ID: 38790074
try this

update A
set street1id = B.id
FROM dbo.benchmarks  A join  dbo.streets B
on A.street1 = B.streetname
0
 

Author Closing Comment

by:rochestermn
ID: 38793314
Worked perfectly!  Guess I didnt need a temp table after all.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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