Update Problem

  • hello

    i want to update a data in grid view

    i have three columns in grid view

    first two column are shift id and date these two column are taken from table 1

    the third column is shift column this column are taken from table 2

    now i want to update a data where shift id and shift column are same

    table 2 have these column

    shift

    shiftid

    and table 1 has these column

    shift id,

    date

    please can u provide me a update query syntax

    thanks

    immad

  • We're not here to do your work for you, although obviously we're happy to help out if there's anything in particular you don't understand. Therefore please will you show us what you've tried so far? Also, you're more likely to get help if you post table DDL and sample data in the form of INSERT statements.

    John

  • Without proper DDL (create table) statements and sample data it is hard for us to understand and help you.

    If I understand correct you have a view with data from 2 different tables. You want to alter the data in the view.

    It is not possible to update two tables in a single statement. So you have to create two seperate update statement, one for each table. Specify the same value for "shift_id" in the WHERE clause of both update statements.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • update shift column with shift id

    for example

    shift id------------shift

    ---1-----------------A

    ---2-----------------B

    after execute query data shows this result

    shift id----------------shift

    ----1--------------------C

    ----2--------------------B

    immad

  • update shift_table

    set shift = case shift_id

    when 1 then 'C'

    when 2 then 'B'

    else shift_id

    end

    where shift_id < 3

    You can expand and/or alter the CASE statement to your specific needs. Also try to get a generic alteration of the new value. Like for example: you could alter the above sample to update shift_table

    set shift = char(ascii(shift)+1)

    where shift_id < 3if you need to take the next character for every value. Then a CASE statement is not required anymore.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • dont fix the values please

    immad

  • immaduddinahmed (7/19/2013)


    dont fix the values please

    ??

    I don't understand what you mean. Please clearify.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • there are lots of shifts in shift table not only 1 and 2

    immad

  • Do you need to change the values in a generic way (i.e.: add a fixed value, replace with a fixed value, etc.)?

    Do you need to change the values in a generic way related to another column (i.e.: add value from column B to column A, depending on value in column B change value of column A to X else to Y, etc.)?

    Do you need to change the values according to user/application input and these input is completely random?

    If possible, provide some real world sample data and include the values before and after the update.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • I AM MAKING A APPLICATION IN c# THERE IS A GRID THAT SHOWS

    SHIFT ID , SHIFT AND DATE

    USER SEARCH DATE AND IN GRID DATE , SHIFT AND SHIFT ID SHOWS

    THEN USER CHANGE SHIFT AND ON SHIFT TABLE THAT SHIFT NAME CHANGE OF THAT ID.

    SHIFT ID AND DATE COME FROM SHIFT DETAILS TABLE

    THIS IS A DATA

    SHIFT ID----------DATE

    -----1------------1/1/2013

    -----2------------2/1/2013

    -----3-----------4/5/2013

    -----4------------6/24/2013

    AND SHIFT COME FROM SHIFT TABLE

    THIS IS A DATA OF SHIFT TABLE

    SHIFT ID----------SHIFT

    -----1------------A

    -----2------------B

    -----3-----------C

    -----4------------D

    WHEN USER EXECUTE UPDATE QUERY ITS CHANGES SHIFT COLUMN VALUE OF SHIFT TABLE

    I HOPE U UNDER STAND SIR

    ONE THING MORE HE CAN ONLY CHANGE A SHIFT FROM THE GRID HE CANNOT CHANGE ID

    immad

  • P.S.: No need to use all capital letters

    You can execute a simple update command to alter the value in the shift_table (the @new_value and @shift_id are variables with the values from the grid)

    update shift_table

    set shift = @new_value

    where shift_id = @shift_id

    If you also need to update the DATA table with the date of the modification, you need to additionally execute the update statement below (use the same value for @shift_id as above statement):

    update data

    set date = getdate()

    where shift_id = @shift_id

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • PLease provide the proper DDL statements and data so that we can help you in your problem....

    Refer this link whever you post any problem:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • immaduddinahmed (7/19/2013)


    I AM MAKING A APPLICATION IN c# THERE IS A GRID THAT SHOWS

    SHIFT ID , SHIFT AND DATE

    USER SEARCH DATE AND IN GRID DATE , SHIFT AND SHIFT ID SHOWS

    THEN USER CHANGE SHIFT AND ON SHIFT TABLE THAT SHIFT NAME CHANGE OF THAT ID.

    SHIFT ID AND DATE COME FROM SHIFT DETAILS TABLE

    THIS IS A DATA

    SHIFT ID----------DATE

    -----1------------1/1/2013

    -----2------------2/1/2013

    -----3-----------4/5/2013

    -----4------------6/24/2013

    AND SHIFT COME FROM SHIFT TABLE

    THIS IS A DATA OF SHIFT TABLE

    SHIFT ID----------SHIFT

    -----1------------A

    -----2------------B

    -----3-----------C

    -----4------------D

    WHEN USER EXECUTE UPDATE QUERY ITS CHANGES SHIFT COLUMN VALUE OF SHIFT TABLE

    I HOPE U UNDER STAND SIR

    ONE THING MORE HE CAN ONLY CHANGE A SHIFT FROM THE GRID HE CANNOT CHANGE ID

    :ermm: Really no need to start posting in all caps when the people here are actually trying to help you considering your tone. "don't fix values plz" isn't a valid response to someone who is attempting to generate code out of thin air because you haven't posted a single line of your own.

    No-one is here to work for you.

  • Thanks Hanshi my problem is solve

    immad

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

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