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
 update from select

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-02-06 : 01:40:32
is it possible to update from select statement?

i did my script which end out need to update.

select... into #toUpdate from ...

the result from #toUpdate is:

update tableA set columnA = ... where .....

How can i update the #toUpdate
I would like to schedult it instead of doing it manually.

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-02-06 : 03:34:19
i tried this but it only will select the result instead of update it.

declare @run nvarchar(max)='select * from #toUpdate'
exec(@run)
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-02-06 : 03:36:16
i tried this but it only will select the result instead of update it.

declare @run nvarchar(max)='select * from #toUpdate'
exec(@run)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-06 : 04:12:29
can you explain what are you trying to achieve ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-02-06 : 04:14:09
would like to schedult to update the records.

update statement will store in a table.

how can i execute update statement to update the records.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-02-06 : 05:12:51
You will need to use Dynamic SQL

see http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -