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.
Author |
Topic |
vignesht50
Yak Posting Veteran
82 Posts |
Posted - 2013-11-08 : 06:58:59
|
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 City21 X PA Chn2 Sathish PA Chn3 Shiva A Cbe17 Venkat M Hyd22 Y SM Cbe18 Vignesh SA HydTable: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'); |
|
GhostX1
Starting Member
6 Posts |
Posted - 2013-11-08 : 08:27:08
|
The following query would change every record that currently has Designation of PA to PAT. Is that what you were after?Update dbo.AppInvent_TestSet Designation='PAT'Where Designation='PA' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-08 : 11:12:58
|
[code]UPDATE tSET Designation = @Designation FROM AppInvent_Test tINNER JOIN AppInvent_Test t1On t1.Designation = t.DesignationAND t1.City = t.CityWHERE t1.EmpID = @EmpID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
vignesht50
Yak Posting Veteran
82 Posts |
Posted - 2013-11-21 : 05:41:07
|
Thanks visakh, got it. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-21 : 07:03:21
|
cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|