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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 problem with update query

Author  Topic 

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2010-09-27 : 15:17:27
hi every body
how can i convert this statements to few line statement? something like loop or i don't know!!!


update formTahavol set v80=v77
update formTahavol set v79=v76
update formTahavol set v78=v75
update formTahavol set v87=v74
update formTahavol set v86=v73
update formTahavol set v85=v72
update formTahavol set v84=v71
....
update formTahavol set v47=v44
update formTahavol set v46=v42

thanks

****<< I Love MTN.SH >>****

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2010-09-27 : 18:10:41
You can merge them into one

UPDATE Table
SET col1 = val1,
col2= val2,
col3 = vale,
...
..coln= valn

unless you have different WHERE clauses for each of these UPDATEs.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

mahdi87_gh
Yak Posting Veteran

72 Posts

Posted - 2010-09-28 : 03:31:29
thanks for answer
but this is not what i want. i have a table formTahavol(v1,v2,v3,....,v77)
now i want to add three columns after v42. so i must add v78,v79,v80 at the end of table, then i have to move data from v43-v77 to v46-v80

****<< I Love MTN.SH >>****
Go to Top of Page
   

- Advertisement -