Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update Problem

Author  Topic 

immad
Posting Yak Master

230 Posts

Posted - 2013-07-19 : 03:16:43
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 uddin ahmed

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-19 : 03:55:11
update which field? with what value?
You just specfied criteria but did give us any information on column to be updated and value to be used

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

immad
Posting Yak Master

230 Posts

Posted - 2013-07-19 : 05:54:57
quote:
Originally posted by visakh16

update which field? with what value?
You just specfied criteria but did give us any information on column to be updated and value to be used

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




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 uddin ahmed
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-19 : 06:25:20
Where does C ad B come from? They're not values present in shift id column so your statement below is incorrect

update shift column with shift id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

immad
Posting Yak Master

230 Posts

Posted - 2013-07-19 : 06:37:48

I EXPLAIN U IN DETAIL

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 uddin ahmed
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-19 : 06:51:49
sounds like this to me

query to serach and get shift details


SELECT [DATE],SHIFT,SHIFTID
FROM Table
WHERE [DATE]= @DateValue

@Datevalue you pass from application

Now when user edit a SHIFT you'll fire a query like this

UPDATE s
SET s.SHIFT= @YourNewShiftValue
FROM SHIFT s
WHERE SHIFTID=@ShiftID

Where @YourNewShiftValue will be tha value user changes in grid
and @ShiftID will have id of the row that user modifies as its value

you need to write code in C# to form the above sql queries in your c# code, pass them to db and execute



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -