?
Solved

Change variables in SQL table

Posted on 2016-09-14
6
Medium Priority
?
147 Views
Last Modified: 2016-09-15
Hi,

How do I change all highlighted to D: drive in SQL with one query.

view.jpg
0
Comment
Question by:Member_2_7967487
6 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 41798913
Use the T-SQL Replace keyword to change subsets of string values.  Will probably want to do this a couple of times to handle all the upper case / lower case scenarios.

UPDATE dbo.Company
SET 
   ACCTdirect = REPLACE (ACCTdirect, 'C:\DataMasons' , 'D:\'), 
   EDIdirect = REPLACE (EDIdirect , 'C:\DataMasons' , 'D:\'), 
   vpEDIdirect = REPLACE (vpEDIdirect, 'C:\DataMasons' , 'D:\'), 
   vpSharedirect = REPLACE (ACCTdirect, 'C:\DataMasons' , 'D:\')

Open in new window

0
 
LVL 43

Expert Comment

by:pcelba
ID: 41798941
You don't need to execute the command several times:
UPDATE dbo.Company
SET 
   ACCTdirect = REPLACE (ACCTdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'), 
   EDIdirect = REPLACE (EDIdirect , 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'), 
   vpEDIdirect = REPLACE (vpEDIdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'), 
   vpSharedirect = REPLACE (ACCTdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:')

Open in new window

Of course, if your columns are case insensitive already then the COLLATE is not necessary.
0
 
LVL 37

Expert Comment

by:Pawan Kumar
ID: 41799068
Try below

UPDATE dbo.Company
SET
   ACCTdirect = REPLACE (ACCTdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'),
   EDIdirect = REPLACE (EDIdirect , 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'),
   vpEDIdirect = REPLACE (vpEDIdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:'),
   vpSharedirect = REPLACE (ACCTdirect, 'C:\DataMasons' COLLATE Latin1_General_CI_AS , 'D:')
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Member_2_7967487
ID: 41799899
Jim's feedback works best. Thank you, Jim!!

Thanks you everyone for your help!
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 41799940
Thanks for the accept.  Good luck with your project.  -Jim

@pcelba and pawan - I'm glad you guys posted, as I didn't know you can combine REPLACE with COLLATE.  I can predict sitting for a SQL 2016 T-SQL exam and getting that as a question, and not answering it correctly if it were not for reading your posts.
0
 
LVL 43

Expert Comment

by:pcelba
ID: 41800070
BTW, I wouldn't say Jim's solution works best it was just faster but it also produces double backslashes on output...  :-)

np for me
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Viewers will learn how the fundamental information of how to create a table.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question