[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL Loop help (temp tables etc)

Posted on 2013-01-17
3
Medium Priority
?
209 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 2000 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

Technology Partners: 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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

656 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