2013-08-30 62 views
0

我需要在我有的表中解決SQL中的問題。SQL使用替換技術更新各種行

我有一個表有不同的列(也有各種行)有一個路線。 I.E.

E:\ file.xml

我需要做的是,檢查至少10列是何其相似,並搜索爲E開頭的單詞:\並替換爲C吧:

是否有一個查詢可以幫助我做到這一點?或者我將不得不一一編輯(因爲我不認爲這是最聰明的方式)。

UPDATE: 表結構

CREATE TABLE [dbo].[CCARD_corporatives](
    [idCorporative] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL, 
    [pathCFD] [varchar](128) NULL, 
    [pathCertificateCFD] [varchar](128) NULL, 
    [pathPrivateKeyCFD] [varchar](128) NULL, 
CONSTRAINT [PK_CCARD_corporatives] PRIMARY KEY CLUSTERED 
(
    [idCorporative] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 


SET IDENTITY_INSERT [dbo].[CCARD_corporatives] ON 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (19, 'E:\file1.xml', 'E:\fil2e.xml', 'E:\file423.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (33, 'E:\file1.xml', 'E:\filer2.xml', 'E:\file123.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (34, 'E:\file1.xml', 'E:\filedsf.xml', 'E:\fil33e.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (36, 'E:\file1.xml', 'E:\f4sdfile.xml', 'E:\fil44e.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (37, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (38, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (40, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (41, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (42, 'E:\file1.xml', 'E:\filgbvdfe.xml', 'E:\fileg dfegdfs.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (43, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (44, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (49, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (50, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (51, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (52, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (53, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (56, 'E:\file1.xml', 'E:\file0067.xml', 'E:\file4323.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (57, 'E:\file1.xml', 'E:\file4234.xml', 'E:\fil555e.xml') 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (64, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (82, NULL, NULL, NULL) 
INSERT [dbo].[CCARD_corporatives] ([idCorporative], [pathCFD], [pathCertificateCFD], [pathPrivateKeyCFD],) VALUES (83, 'E:\file1.xml', 'E:\file443.xml', 'E:\fil4324e.xml') 
SET IDENTITY_INSERT [dbo].[CCARD_corporatives] OFF 
+0

什麼RDBMS是您使用:\,試試這個? –

+0

SQL Server Management Studio 2008 R2 – Victor

+0

表的結構是什麼?可能是任何一列中的路線價值,或者您是否具有該值的特定列? – Silvano

回答

0

如果要更新,實際上具有任何價值至極每列隨e開頭:

UPDATE [CCARD_corporatives] 
SET pathCFD = CASE 
      WHEN pathCFD LIKE 'e:\%' 
      THEN REPLACE(pathCFD,'e:\','c:\') 
      ELSE pathCFD 
      END, 
     pathCertificateCFD = CASE 
         WHEN pathCertificateCFD LIKE 'e:\%' 
         THEN REPLACE(pathCertificateCFD,'e:\','c:\') 
         ELSE pathCertificateCFD 
        END, 
     pathPrivateKeyCFD = CASE 
         WHEN pathPrivateKeyCFD LIKE 'e:\%' 
         THEN REPLACE(pathPrivateKeyCFD,'e:\','c:\') 
         ELSE pathPrivateKeyCFD 
        END;