SQL how do I remove trailing spaces? [duplicate] - sql

This question already has answers here:
Empty space at the end of SQL Server query results
(3 answers)
Closed 8 months ago.
I'm currently working in an SQL database where a column has trailing spaces.
The spaces in question show up as %20 in the browser url.
I've been able to remove them with a select query but whenever I convert it to an update an set query it doesn't seem to work, any input would be appreciated.
Working select query:
select [dbo].[udf-Str-Strip-Control](identifier)
from [AHDRC].[dbo].[artworks]
Broken update query:
update [AHDRC].[dbo].[artworks]
SET [identifier] = [dbo].[udf-Str-Strip-Control](identifier);
SELECT [identifier]
From [AHDRC].[dbo].[artworks];
I am currently using SQL server management studio
[identifier] is a nchar(128)
Apologies if anything is unclear / badly formatted.

[identifier] was a nchar(128) causing trailing spaces.

Related

Oracle SQL - Escape ampersand in field name [duplicate]

This question already has answers here:
How to escape ampersand in TOAD?
(3 answers)
Closed 3 years ago.
I've seen a bunch of related posts, but none yet that resolve my specific question.
In Oracle SQL I need to do something like this:
SELECT field1 "Eggs&Cheese"
FROM table1;
But it reads the &Cheese and wants to do parameter substitution. I just want the field name to be Eggs&Cheese
I saw this post Escape ampersand with SQL Server, but Oracle does not like the bracket [] syntax.
And also Escaping ampersand character in SQL string, but that is escaping the ampersand in a value string, not a label string.
The substitution is related to tool you are using and has nothing to do with column alias.
db<>fiddle demo
Depending on the tool you could disable it like "set define off".
Related: Set define off not working in Oracle SQL Developer & How to escape ampersand in TOAD?
You have to set the escape. Works in Oracle SQL Developer.
set escape \
SELECT field1 "Eggs\&Cheese" FROM table1;
After your work is done you can set it off.
set escape off

Replacing weird control characters from sql server table [duplicate]

This question already has answers here:
SQL Server - Remove all non-printable ASCII characters
(4 answers)
Closed 4 years ago.
I have a sql server table where control characters appear when column is copied and pasted into notepad. I need to remove/replace these control characters. For example here is a text i copied from my sql server table into notepad
How do i remove "OSC". I have searched the net and here but cant find anything on this. Table was imported from SSIS as ANSI (i also tried data conversion in ssis to convert the column to ascii but still to no avail).
"OSC" is CHAR(157). Try using REPLACE(Values, CHAR(157), ''). If it works then you can update in the table. Hope it helps.

SQL 'LIKE' clause with apostrophe [duplicate]

This question already has answers here:
How do I search for names with apostrophe in SQL Server?
(9 answers)
Closed 5 years ago.
If im trying to search for 'RYAN'S TEAM' in sql it doesnt like the fact that i have an apostrophe ' in RYAN'S and detects that as the end of the LIKE statement.
[Team] LIKE '%RYAN'S TEAM%'
It recognises the whole next line as red in sql server. Is there anyway around this as RYAN'S TEAM is the way it is stored in the database.
This will work:
[Team] LIKE '%RYAN''S TEAM%'
You just have to double the quote chars.

Why some rows can be inserted into and some cannot? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
When I use the Cashier table or some other tables that have small amounts of records the process proceeds and table is inserted into the external database. But when I change the cashier into the transaction database (400k+ records), Visual Studio reports an error near "Transaction" Help would be appreciated thanks.
Cashier Database (working)
Dim query As String = "select * into MyDatabase2.dbo.Cashier from bos_primary_db.dbo.Cashier"
Transaction Database (not working)
Dim query As String = "select * into MyDatabase2.dbo.Transaction from bos_primary_db.dbo.Transaction"
This is the error message:
Incorrect syntax near the keyword 'Transaction'
this is probably because Transaction is a reserved word in SQL.
Depending on your RDBMS (that you didn't specify), there are ways to "escape" it:
for Sql Server, you should wrap reserved words in square brackets:
select * into MyDatabase2.dbo.[Transaction] from bos_primary_db.dbo.[Transaction]
For MySql you should use an apostrophe:
select * into MyDatabase2.dbo.`Transaction` from bos_primary_db.dbo.`Transaction`
For Oracle you should use double quotes:
select * into MyDatabase2.dbo."Transaction" from bos_primary_db.dbo."Transaction"
Note: You should always try to avoid using reserved words. This link describes my favorite way of do it.

How can I remove the leading quote? [duplicate]

This question already has answers here:
CSV import in SQL Server 2008
(3 answers)
Closed 8 years ago.
I am using BULK INSERT to import a text file into a table.
The data imports OK but is quoted. for example
"1235","Bob Dylan","Dylan","Bob"
I have read a bit on this and have I created a format file using BCP that resolves the problem except the leading quote. ie:
"1235,Bob Dylan,Dylan,Bob
How can I remove the leading quote
In the past I have used an XML format file with a dummy row of 1 character length. Maybe someone else has a more elegant solution but that worked for me.