Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Update Problem Expand / Collapse
Author
Message
Posted Friday, July 19, 2013 1:22 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 5:38 AM
Points: 102, Visits: 312
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
Post #1475298
Posted Friday, July 19, 2013 1:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:15 AM
Points: 5,424, Visits: 10,083
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
Post #1475302
Posted Friday, July 19, 2013 2:14 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:06 AM
Points: 2,390, Visits: 2,925
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’! **
Post #1475317
Posted Friday, July 19, 2013 4:03 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 5:38 AM
Points: 102, Visits: 312
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
Post #1475348
Posted Friday, July 19, 2013 4:11 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:06 AM
Points: 2,390, Visits: 2,925
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 < 3

if 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’! **
Post #1475353
Posted Friday, July 19, 2013 4:13 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 5:38 AM
Points: 102, Visits: 312
dont fix the values please
Post #1475354
Posted Friday, July 19, 2013 4:16 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:06 AM
Points: 2,390, Visits: 2,925
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’! **
Post #1475356
Posted Friday, July 19, 2013 4:18 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 5:38 AM
Points: 102, Visits: 312
there are lots of shifts in shift table not only 1 and 2
Post #1475358
Posted Friday, July 19, 2013 4:24 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:06 AM
Points: 2,390, Visits: 2,925
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’! **
Post #1475361
Posted Friday, July 19, 2013 4:33 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 5:38 AM
Points: 102, Visits: 312
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
Post #1475365
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse