Reputation: 2204
I have a table that contain a list of properties that will be visible to user. but I inserted data in wrong format,I want to swap values of [ActionName]
with [ControllerName]
name without creating a temporary table.
SELECT [MenuID]
,[MenuName]
,[MenuMasterID]
,[ActionName]
,[ControllerName]
,[ImageClassName]
,[MainOrderID]
,[SubOrderID]
FROM [DEV_CMS_Medical].[dbo].[SEC_Menus]
Upvotes: 0
Views: 74
Reputation: 176244
Use assigment/aliasing if you want to swap only when querying
SELECT
t.[MenuID]
,t.[MenuName]
,t.[MenuMasterID]
,[ActionName] = t.[ControllerName]
,[ControllerName] = t.[ActionName]
,t.[ImageClassName]
,t.[MainOrderID]
,t.[SubOrderID]
FROM [DEV_CMS_Medical].[dbo].[SEC_Menus] t;
Use Update when you want swap underlying data:
UPDATE [DEV_CMS_Medical].[dbo].[SEC_Menus]
SET [ActionName] = [ControllerName]
,[ControllerName] = [ActionName];
Upvotes: 1
Reputation: 172628
You can try to rename the column names like this:
sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
For this you need to first set the OldColumnName to some dummy name. Something like this:
sp_RENAME '[SEC_Menus].[ActionName]' , '[ControllerNameDummy]', 'COLUMN'
Upvotes: 0
Reputation: 20862
update dbo.SEC_Menus
set ActionName = ControllerName,
ControllerName = ActionName
Upvotes: 1
Reputation: 8865
UPDATE [DEV_CMS_Medical].[dbo].[SEC_Menus]
SET ActionNamec = ControllerName,
ControllerName = ActionName
Or IF you want show the data with out any manipulation just use the alias name for required columns
Upvotes: 1