Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Update

Author  Topic 

shiyam198
Yak Posting Veteran

94 Posts

Posted - 2012-06-20 : 11:37:41
Hi Guys,

I have a quick question.

I have 2 tables and the main columsn are the following:

ts_performance - Performance_id, performance_start_date, performance_description, performance_name, performance_series_id,
ts_series - series_id, series_name, series_description

The tables are connected on ts_performance.performance_series_id and ts_series.series_id. I can bring the combined data like this.


select performance_start_date, performance_description, series_description, performance_name, performance_series_id, series_name, series_description from ts_performance
inner join ts_series
on ts_performance.performance_series_id = ts_series.series_id
where performance_start_date > '2012-06-20 14:00:00.000'


My intension is to update the performance_description field in ts_performance with series_description in ts_series.

The way I can think of it is creating a table with performance_id, performance_description and series_description from the above data set.

and update the ts_performance table with the update.

Is there another way to acheive that without creating a middle table.

Thanks for your time.

Regards,
Shiyam

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-20 : 11:48:21
I think this should do the trick, assumin a one-ton-one relationship

UPDATE perf
SET performance_description = ser.series_description
FROM ts_performance perf
INNER JOIN join ts_series ser
on perf.performance_series_id = ser.series_id

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

shiyam198
Yak Posting Veteran

94 Posts

Posted - 2012-06-20 : 12:50:58
THANKS A LOT
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-20 : 12:56:11
You're welcome. Don't forget your where clause, and run it as a select statement first to make sure it does exactly what you want.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -