Solved

SQL - Select and Replace Syntax

Posted on 2015-02-12
9
150 Views
Last Modified: 2015-02-12
I have a bunch of PDF drawings that are listing in a BRIDGEPHOTO Table in SQL Server 2012 , Problem is some of the pdf names include the "&" symbol. This is a reserved word in ESRI and the attachments are not working.

I would just like to Delete that from the name all together.
So Plan&Profile becomes PlanProfile or Plan_Profile
I can replace with and "_" as well. Either way is good with me.

SELECT REPLACE(AliasName,'&', '')
from [BRIDGEPHOTO]
Where AliasName Like '&'
GO

I'm not sure if this is right and was hoping to double check, Plus get some feedback on the best way to do this.
Thanks
0
Comment
Question by:PtboGiser
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 48

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40605686
Should be:
SELECT REPLACE(AliasName,'&', '')
 from [BRIDGEPHOTO]
 Where AliasName Like '%&%'

Open in new window


You can also use this update statement:
UPDATE [BRIDGEPHOTO]
SET AliasName = REPLACE(AliasName,'&', '')

Open in new window

0
 
LVL 18

Expert Comment

by:Simon
ID: 40605694
I could be off the mark here, but is it the actual PDF files that you have stored in the table, or pointers to their location?

If what you have stored are pointers, doing any replace on the filenames may break the link to the source documents.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40605701
Almost.

The third line should read

Where AliasName Like '%&%'

However, if you actually want to replace the original table, then you should use

Update [BRIDGEPHOTO]
Set AliasName = REPLACE(AliasName,'&', '')
Where AliasName Like '%&%'
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:PtboGiser
ID: 40605702
Pointers, I have a second question posted on how to rename the actually pdf file stored in Windows Explorer.
0
 
LVL 48

Expert Comment

by:Vitor Montalvão
ID: 40605709
You can't have the symbol '&' in files.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40605720
You can! ampersand in file.
0
 

Author Comment

by:PtboGiser
ID: 40605737
0
 
LVL 48

Expert Comment

by:Vitor Montalvão
ID: 40605742
I can see now. Only in Windows. I've tried in the Command Prompt and I couldn't. You need to put the filename in quotes "ABC&D.txt" to it can accept.
0
 

Author Closing Comment

by:PtboGiser
ID: 40605803
Thanks Crew, Got it. I just don't work enough with these syntax's to know them without some guidance
Cheers
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TSQL Challenge... 7 35
Stored Proc - Rewrite 42 58
SQL Dump exec output to table 3 21
What is the best way to use power bi and ssrs 3 23
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

856 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