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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 update statement help

Author  Topic 

neil_akoga
Yak Posting Veteran

56 Posts

Posted - 2008-12-16 : 04:53:18
I have a gridview on my asp.net site that's using a view as its select on my datasource. the select is below.

can anybody help me by showing how i should be writing my update statement

SELECT tblTOD.title, tblTOD.fName, tblTOD.sName,
tblTOD.position, tblTOD.company, tblTOD.email,
tblTOD.telephone, tblT.courseName, tblTO.orderID, tblT.courseId,
tblTOD.freeplace, tblTO.pricePerDelegate, tblTOC.title AS ctitle,
tblTOC.fName AS cfname, tblTOC.sName AS csname,
tblTOC.company AS ccompany, tblTOC.address1, tblTOC.address2,
tblTOC.address3, tblTOC.town, tblTOC.county,
tblTOC.postcode, tblTOC.country, tblTOC.email AS cemail,
tblTOC.telephone AS ctel, tblTOC.position AS cposition, tblTO.orderType,
tblTO.authorised, tblTOD.dietary, tblT.courseDate, tblT.courseVenue,
tblT.courseLocation
FROM tblTO INNER JOIN
tblTOD ON tblTO.orderID = tblTOD.orderID INNER JOIN
tblT ON tblTO.courseID = tblT.courseId INNER JOIN
tblTOC ON tblTOD.orderID = tblTOC.orderID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 05:01:04
what are fields you want to update? also which is table to be updated?
Go to Top of Page

neil_akoga
Yak Posting Veteran

56 Posts

Posted - 2008-12-16 : 05:40:36
i want to update all the tables and all the fields in the select statment tblTOD, tblTO, tblTOC and tblT
Go to Top of Page

JamesRyan
Starting Member

18 Posts

Posted - 2008-12-16 : 05:41:58
The following link will show you how to use an update statement across a join, and how to query from both tables if necessary.

http://www.sqlhowto.co.uk/post/how-can-i-use-an-update-statement-containing-a-join-.html

James Ryan
www.sqlhowto.co.uk
Go to Top of Page

neil_akoga
Yak Posting Veteran

56 Posts

Posted - 2008-12-17 : 11:08:39
ok, so the example you linked to makes sense

UPDATE Table1
SET Column1 = 'new value'
FROM Table1
INNER JOIN Table2
ON Table1.ID = Table2.ID

how do i update values in all the tables

is it something like this?

UPDATE Table1
SET Column1 = 'new value'
UPDATE Table2
Set column2 = 'new value'
FROM Table1
INNER JOIN Table2
ON Table1.ID = Table2.ID
where table1.column1 = 'some value'
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-17 : 11:16:50
it should be two separate updates

UPDATE Table1
SET Column1 = 'new value'
FROM Table1
INNER JOIN Table2
ON Table1.ID = Table2.ID
where table1.column1 = 'some value'


UPDATE Table2
Set column2 = 'new value'
FROM Table1
INNER JOIN Table2
ON Table1.ID = Table2.ID
where table1.column1 = 'some value'
Go to Top of Page
   

- Advertisement -