Need help with a query please

  • IDlotCodelotCurrentQtylotNetWeightNbPal spCode

    6401130475220030 0 0 NULL

    10011304752200316 516 1 SP0113000033

    11011304752200314 457 1 SP0113000034

    6501130475220040 0 0 NULL

    12011304752200419 480 1 SP0113000033

    13011304752200421 526 1 SP0113000034

    19011304752200429 670 1 SP0113000034

    let's assume this recordset as an example. I need to update the fields lotCurrentQty, lotNetWeight and NbPal to zero for all the other instances of spCode, but the first one. In this case, row ID 12 (related to row ID 10) and row ID 13 and 19 (related to row 11) should be update to 0. How can I do that??

    It's a SQL 2000.

    thanks a lot for your time and help

  • In order to help we will need a few things:

    1. Sample DDL in the form of CREATE TABLE statements

    2. Sample data in the form of INSERT INTO statements

    3. Expected results based on the sample data

    Please take a few minutes and read the first article in my signature for best practices when posting questions.

    Also, you said something about the "first" one. There is no concept of order in a table. If you want an order you have to define it. That means there must be something to order by.

    _______________________________________________________________

    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/

  • Just check if you are looking some thing like this Query,

    update testtable1

    set lotCurrentQty = 0,

    lotNetWeight = 0 ,

    NbPal = 0

    where id not in (

    Select * from testtable1

    where spcode is not null

    group by spCode)

    But Please do prepare some DDL and INSERT statements as Sean Lange mentioned, will help us to help you.

  • yeah, it's something like that! I'll work around that! thanks!

Viewing 4 posts - 1 through 3 (of 3 total)

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