SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update query for similar values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vignesht50
Yak Posting Veteran

82 Posts

Posted - 11/08/2013 :  06:58:59  Show Profile  Reply with Quote
Hi,

I have a grid like this and when I change Designation value of Name X from PA to PAT, this change should reflect to Sathish Designation too. Changing similar values should reflect all over the grid. Like update database on change of value of similar kind. Any suggestions on update query?

By far I use this query to update the grid. So a where clause should be used now to update the grid to fit this scenario. Correct me if I am wrong.
("UPDATE AppInvent_Test SET Name = @Name, Designation = @Designation, City = @City WHERE EmpID = @EmpID");


EmpID Name Designation City
21 X PA Chn
2 Sathish PA Chn
3 Shiva A Cbe
17 Venkat M Hyd
22 Y SM Cbe
18 Vignesh SA Hyd

Table:
CREATE TABLE [dbo].[AppInvent_Test](
[EmpID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NULL,
[Designation] [varchar](100) NULL,
[City] [varchar](50) NULL
) ON [PRIMARY]

insert into AppInvent_Test values('X', 'PA','Chn');
insert into AppInvent_Test values('Sathish', 'PA','Chn');
insert into AppInvent_Test values('Shiva', 'A','Cbe');
insert into AppInvent_Test values('Venkat', 'M','Hyd');
insert into AppInvent_Test values('Y', 'SM','Cbe');
insert into AppInvent_Test values('Vignesh', 'SA','Hyd');

Edited by - vignesht50 on 11/08/2013 07:58:27

GhostX1
Starting Member

6 Posts

Posted - 11/08/2013 :  08:27:08  Show Profile  Reply with Quote
The following query would change every record that currently has Designation of PA to PAT. Is that what you were after?

Update dbo.AppInvent_Test
Set Designation='PAT'
Where Designation='PA'

Edited by - GhostX1 on 11/08/2013 08:27:35
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/08/2013 :  11:12:58  Show Profile  Reply with Quote

UPDATE t
SET Designation = @Designation 
FROM AppInvent_Test t
INNER JOIN AppInvent_Test t1
On t1.Designation = t.Designation
AND t1.City = t.City
WHERE t1.EmpID = @EmpID


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

vignesht50
Yak Posting Veteran

82 Posts

Posted - 11/21/2013 :  05:41:07  Show Profile  Reply with Quote
Thanks visakh, got it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/21/2013 :  07:03:21  Show Profile  Reply with Quote
cool

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000