Professional Web Applications Themes

update statement - Microsoft SQL / MS SQL Server

Hi Try: Update T1 SET Fld2 = T2.Fld2 FROM Table1 T1 JOIN Table2 T2 ON T1.Fld1 = T2.Fld1 John "TomR" <trukavinacompucom-inc.com> wrote in message news:030801c3463b$c7b81290$a101280aphx.gbl... > Can someone please give me a hand.... Here is what I am > trying to do.. I have 2 tables (table1 and table2) I want > to take the data from table2 and replace the data in > table one but only if field1 in each table matches. It > sounds pretty simple but I can seem to get it. > > Thanks for any help......

  1. #1

    Default Re: update statement

    Hi

    Try:

    Update T1
    SET Fld2 = T2.Fld2
    FROM Table1 T1 JOIN Table2 T2 ON T1.Fld1 = T2.Fld1

    John

    "TomR" <trukavinacompucom-inc.com> wrote in message
    news:030801c3463b$c7b81290$a101280aphx.gbl...
    > Can someone please give me a hand.... Here is what I am
    > trying to do.. I have 2 tables (table1 and table2) I want
    > to take the data from table2 and replace the data in
    > table one but only if field1 in each table matches. It
    > sounds pretty simple but I can seem to get it.
    >
    > Thanks for any help...

    John Bell Guest

  2. #2

    Default Update Statement

    Can someone please give me a hand with this... Here is
    what I an trying to do. I have two tables (Table1 and
    table2) I want take the data from Table2 and replace the
    data (row) in table1 but only if field1 matches. It seems
    easy but I just cant get it.
    Thanks in advance for any help.
    TomR Guest

  3. #3

    Default Update Statement

    Hi,

    may this tool can help you ...

    [url]http://www.sqlscripter.com[/url]

    Primarily if you do this job often or on different
    servers.

    Regards
    >-----Original Message-----
    >Can someone please give me a hand with this... Here is
    >what I an trying to do. I have two tables (Table1 and
    >table2) I want take the data from Table2 and replace the
    >data (row) in table1 but only if field1 matches. It
    seems
    >easy but I just cant get it.
    >Thanks in advance for any help.
    >.
    >
    SQL Scripter Guest

  4. #4

    Default Re: Update statement

    Priti,

    If you are using Sql2000 then, you can create a userdefined function to get
    comma delimited states for a given age.

    create function getStates(age as int)
    RETURNS varchar(200)
    AS
    Begin

    Declare StatesList varchar(200)
    Select StatesList = coalesce(StatesList + ',','') + addr from T2 where
    age=age
    RETURN( StatesList)
    End

    Update T1 set addr= testdb.dbo.getStates(age) from t1


    HTH,
    Praveen
    MCDBA, MCSD

    "priti" <com> wrote in message
    news:063c01c35e22$1d4a1840$gbl... 


    praveen Guest

  5. #5

    Default Re: Update statement

    Priti,

    The question is why ?
    Storing comma seperated values in a datebase column is rather eccentric.
    You might want to have another look at the structure of your tables.
    Normalisation makes data manipulation sooo much easier.

    Regards
    AJ

    "priti" <com> wrote in message news:063c01c35e22$1d4a1840$gbl... 


    Andrew Guest

  6. #6

    Default Update statement

    Thanks praveen,

    But is it possible to do with some set statements.
    this way I have to loop the functions through all the
    ages, which is same as writing a cursor.

    Thanks.

     
    addr 
    should 
    priti Guest

  7. Moderated Post

    Default Re: Update statement

    Removed by Administrator
    Joe Guest
    Moderated Post

Similar Threads

  1. Select-And-Update in one statement?
    By Ignoramus23298 in forum MySQL
    Replies: 1
    Last Post: May 19th, 07:02 PM
  2. Update Statement error
    By ldebono in forum Coldfusion Database Access
    Replies: 2
    Last Post: March 22nd, 06:25 PM
  3. sql - statement for update - id
    By pilem17 in forum Coldfusion Database Access
    Replies: 5
    Last Post: October 3rd, 06:15 AM
  4. Generated Update Statement
    By Matt M. in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: January 30th, 04:41 PM
  5. Update and Select Statement
    By hngo01 in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 4th, 01:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139