Update Query

  • Hi:

    I have this query (below). MaterialDesc is the fieldname, and I want to append data to the value. I'm certain I have not selected the value right, and this may be all the help I need. Of course maybe there is something else obvious, or a better way to do this.

    Than ks in advance for any help you can provide!

    UPDATE

    SELECT TOP (2000) gauge, material, materialNum, materialDesc, Type

    FROM Material_VendorSourced

    WHERE (materialDesc LIKE 'SHT ALZ%')

    Material_VendorSourced set materialDesc = replace (MaterialDesc, MaterialDesc, MaterialDesc + ' ASTM A463')

  • steve.anderson 7639 (6/28/2011)


    Hi:

    I have this query (below). MaterialDesc is the fieldname, and I want to append data to the value. I'm certain I have not selected the value right, and this may be all the help I need. Of course maybe there is something else obvious, or a better way to do this.

    Than ks in advance for any help you can provide!

    UPDATE

    SELECT TOP (2000) gauge, material, materialNum, materialDesc, Type

    FROM Material_VendorSourced

    WHERE (materialDesc LIKE 'SHT ALZ%')

    Material_VendorSourced set materialDesc = replace (MaterialDesc, MaterialDesc, MaterialDesc + ' ASTM A463')

    You seem to be on the right track but a few things are slightly out of place.

    Update Material_VendorSourced set materialDesc = MaterialDesc + ' ASTM A463'

    where materialDesc LIKE 'SHT ALZ%'

    Not sure what your top 2000 was. Are you trying to only update 2,000 records that meet the where clause. If so you would need to know what the top 2,000 records are by adding an order by clause.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thanks!

  • Joe, I suspect the OP won't find your post very useful.

    Nor do I, indeed.

    -- Gianluca Sartori

  • CELKO (6/29/2011)


    As usual, your real problems are conceptual, not coding.

    "As usual?"

    This is extremely unhelpful. You do realize that this poster is a newbie in the forums, yes? Or do you not look at rankings and number of posts before you decide to make your assumptions?

    It almost seems like you want to chase people away from the SSC forums. Remember, these forums that are meant to help those who need answers and don't always know what we know or agree with the things that we believe. High-handed comments like this are unnecessary and certainly won't make the people you're conversing with willing to listen to your point of view.

    It might help if you switch from the "beat them with the stick" to the "encourage them with the carrot" approach. People might be more willing to listen to your point of view if you give them a reason to other than "I told you you're wrong."

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Sean Lange (6/28/2011)


    Not sure what your top 2000 was. Are you trying to only update 2,000 records that meet the where clause. If so you would need to know what the top 2,000 records are by adding an order by clause.

    I agree with Sean. It seems as if you're trying to do 2 different things at once. Could you give us some sample data pre-Update and post-Update (tell us which is which) so we can see what you're trying to achieve?

    Put it in DDL format, please, such as Insert statements, and a Create Table statement that we can use for testing to assist you.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • I appreciate all of your replies. This is all good stuff, and yes I am relatively new to direct SQL statements vs .NET development in SQL. I am also one to appreciate ISO standards, best practices, etc. so I will study these things at a later time.

    Thanks.

  • Don't get too hung up on it. Joe is a really smart guy but he admits his online personality is intentionally arrogant. He hits that nail on the head with just about every post. If you filter through all the history, insults about how you name things, and the way you think, he pretty much posted the exact same update statement I did. His intentions are good but the method he uses is often very obtuse and pretty rude.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • steve.anderson 7639 (6/29/2011)


    I appreciate all of your replies. This is all good stuff, and yes I am relatively new to direct SQL statements vs .NET development in SQL. I am also one to appreciate ISO standards, best practices, etc. so I will study these things at a later time.

    Thanks.

    Sounds good. Just don't take anythink Celko says too seriously. He has issues with anything that violates "my way or the highway" theories that are important to his personal income. (He writes books on the standards. Nobody would buy them if they didn't feel the need to follow the specific standards he writes books on. Hence, not doing it his way = less books sold = less $ for Joe.)

    Establishing and following standards matters. But Joe goes overboard on pushing it, for financial reasons so far as I can tell.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • CELKO (6/29/2011)


    You also have no idea what ISO-11179 naming rules for data elements are. {snip} In RDBMS, data elements are universal and need exact names

    UPDATE Foobar

    SET a = b, b = a;

    In ANSI/ISO Standard SQL, you can use row constructors to say things like:

    UPDATE Foobar

    SET (a, b)

    = (SELECT x, y

    FROM Floob AS F1

    WHERE F1.keycol= Foobar.keycol);

    It would really be nice if you practiced what you preach. And give up on the childish "Foobar" name... it's not even spelled correctly. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • CELKO (6/29/2011)


    Do you often update things at random? Does your boss know?

    I don't care who ya are, that's funny right there. 😀

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

  • Jeff Moden (6/29/2011)


    ... it's not even spelled correctly.

    http://en.wikipedia.org/wiki/Foobar

  • SQLkiwi (6/30/2011)


    Jeff Moden (6/29/2011)


    ... it's not even spelled correctly.

    http://en.wikipedia.org/wiki/Foobar

    Thanks, Paul. I was wondering why Jeff was saying that, but I forgot about the real fubar acronym.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (7/1/2011)


    SQLkiwi (6/30/2011)


    Jeff Moden (6/29/2011)


    ... it's not even spelled correctly.

    http://en.wikipedia.org/wiki/Foobar

    Thanks, Paul. I was wondering why Jeff was saying that, but I forgot about the real fubar acronym.

    You don't even want to know the real origin of "dog'n'pony show". 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Well...This is pretty much what I always thought it originated from.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply