0

私が持っているテーブルで SQL の問題を解決する必要があります。

ルートを持つさまざまな列 (およびさまざまな行) を持つテーブルがあります。IE

E:\file.xml

私がする必要があるのは、よく似ている列を少なくとも 10 列チェックし、E:\ で始まる単語を検索して C: に置き換えることです。

それを行うのに役立つクエリはありますか? または、それらを 1 つずつ編集する必要がありますか (それが最も賢明な方法だとは思わないため)。

更新: テーブル構造

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
4

1 に答える 1

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;
于 2013-08-30T18:17:26.007 に答える