![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
could somebody give me an example of how to write a cursor that will up date fields within a table from a table of the same design. this will be |
#3
| |||
| |||
|
|
OK From what I think I understand of your problem you do not need to use a cursor. If they are in the same database you can easily do UPDATES UPDATE A SET A.Field = B.Field FROM TABLE1 A JOIN TABLE2 B ON A.KeyCol = B.KeyCol Even if not in the same DB you can use this INSERTS INSERT TABLE1(col list) SELECT <T2 Col List) FROM TABLE2 T2 LEFT OUTER JOIN TABLE1 T1 ON T2.KeyCol = T1.KeyCol WHERE T1.KeyCol IS NULL If ths is not what you mean then can you please expand a little. -- ---------------------------- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.allisonmitchell.com - Expert SQL Server Consultancy. www.SQLDTS.com - The site for all your DTS needs. I support PASS - the definitive, global community for SQL Server professionals - http://www.sqlpass.org "shane" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message news:F475DFC4-5F6E-4C13-B88D-20CC94AD5B14 (AT) microsoft (DOT) com... could somebody give me an example of how to write a cursor that will up date fields within a table from a table of the same design. this will be used to update existing data and to add new. |
#4
| |||
| |||
|
|
could somebody give me an example of how to write a cursor that will u date fields within a table from a table of the same design. this will b |
#5
| |||
| |||
|
|
thanks for that. When would you use a cursor and a trigger then? Cheers ----- Allan Mitchell wrote: ----- OK From what I think I understand of your problem you do not need to use a cursor. If they are in the same database you can easily do UPDATES UPDATE A SET A.Field = B.Field FROM TABLE1 A JOIN TABLE2 B ON A.KeyCol = B.KeyCol Even if not in the same DB you can use this INSERTS INSERT TABLE1(col list) SELECT <T2 Col List) FROM TABLE2 T2 LEFT OUTER JOIN TABLE1 T1 ON T2.KeyCol = T1.KeyCol WHERE T1.KeyCol IS NULL If ths is not what you mean then can you please expand a little. -- ---------------------------- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.allisonmitchell.com - Expert SQL Server Consultancy. www.SQLDTS.com - The site for all your DTS needs. I support PASS - the definitive, global community for SQL Server professionals - http://www.sqlpass.org "shane" <anonymous (AT) discussions (DOT) microsoft.com> wrote in message news:F475DFC4-5F6E-4C13-B88D-20CC94AD5B14 (AT) microsoft (DOT) com... could somebody give me an example of how to write a cursor that will up date fields within a table from a table of the same design. this will be used to update existing data and to add new. |
#6
| |||
| |||
|
|
thanks for that When would you use a cursor and a trigger then Cheer ----- Allan Mitchell wrote: ---- OK From what I think I understand of your problem you do not need t use cursor If they are in the same database you can easily d UPDATE UPDATE SET A.Field = B.Fiel FROM TABLE1 A JOIN TABLE2 ON A.KeyCol = B.KeyCo Even if not in the same DB you can use thi INSERT INSERT TABLE1(col list SELECT <T2 Col List FROM TABLE2 T2 LEFT OUTER JOIN TABLE1 T ON T2.KeyCol = T1.KeyCo WHERE T1.KeyCol IS NUL If ths is not what you mean then can you please expand a little -- --------------------------- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP www.allisonmitchell.com - Expert SQL Server Consultancy www.SQLDTS.com - The site for all your DTS needs I support PASS - the definitive, global communit for SQL Server professionals - http://www.sqlpass.or "shane" <anonymous (AT) discussions (DOT) microsoft.com> wrote in messag news:F475DFC4-5F6E-4C13-B88D-20CC94AD5B14 (AT) microsoft (DOT) com.. could somebody give me an example of how to write a cursor tha will u date fields within a table from a table of the same design. this wil b used to update existing data and to add new |
![]() |
| Thread Tools | |
| Display Modes | |
| |