SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update from select
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

404 Posts

Posted - 02/06/2014 :  01:40:32  Show Profile  Reply with Quote
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

404 Posts

Posted - 02/06/2014 :  03:34:19  Show Profile  Reply with Quote
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

404 Posts

Posted - 02/06/2014 :  03:36:16  Show Profile  Reply with Quote
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)

Singapore
17595 Posts

Posted - 02/06/2014 :  04:12:29  Show Profile  Reply with Quote
can you explain what are you trying to achieve ?


KH
Time is always against us

Go to Top of Page

peace
Constraint Violating Yak Guru

404 Posts

Posted - 02/06/2014 :  04:14:09  Show Profile  Reply with Quote
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)

Singapore
17595 Posts

Posted - 02/06/2014 :  05:12:51  Show Profile  Reply with Quote
You will need to use Dynamic SQL

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


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000