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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Yak Posting Veteran

82 Posts

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

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

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

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

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

Very Important crosS Applying yaK Herder

52326 Posts

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

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

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

Very Important crosS Applying yaK Herder

52326 Posts

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

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.05 seconds. Powered By: Snitz Forums 2000