sas proc sql escape ' (apostrophe) - sql

Is it possible to put an apostrophe into the label when using proc sql?
proc sql;
create table palim
as select palim label='palim's palim'
from palim;
quit;
This will not work, because sas thinks the apostrohe is the end of the label.
I did not manage to get it to work with escape sas community question
This questions is specifically for proc sql, since using double quotes will not work here.

Either switch to using double quote character " to quote your string literal so that the character used on the outside is not contained in the string.
label="palim's palim"
Or double up any embedded quote characters that match the character used on the outside.
label='palim''s palim'
You can use either single or double quote characters to quote string literals in SAS. The only reason they would not work in PROC SQL would be if you added the dquote=ansi option to the proc sql statement. Then values inside double quotes are interpreted as names instead of string literals.

Use % to escape single quote.
proc sql;
create table palim
as select palim label='palim%'s palim'
from palim;
quit;
Can also uso double single quote.
proc sql;
create table palim
as select palim label='palim''s palim'
from palim;
quit;
The escape clause works LIKE expressions.

Related

SQL Server query with symbol (')

How can I make a query to see if any record have the value (')?
I have tried this:
Select * from table where column LIKE '%'%' and other variants and still get sintax error.
And i have the same problem when I do a query like:
Select * from table where column == 'hello'world'
I have in the database a record stored with hello'world
I guess that bot questions have the same answer.
You just have to escape it by using the single quote twice (''), It will be considered as the single quote rather than the starting/ending of the string as follows:
Select * from table where column LIKE '%''%'
You can also use the QUOTED_IDENTIFIER:
According to documentation, When QUOTED_IDENTIFIER is OFF, Literals can
be delimited by either single or double quotation marks. If a literal
string is delimited by double quotation marks, the string can contain
embedded single quotation marks, such as apostrophes.
You can use it as follows:
SET QUOTED_IDENTIFIER OFF;
Select * from table where column LIKE "%'%"
SET QUOTED_IDENTIFIER ON;
' has to be doubled:
Select * from tab where col LIKE '%''%'

insert Single Quotation Marks in sql

I want to insert " exec e_Report.dbo.FTX_FA_Aging_Report_sp 'FACloedAgingReport' " in AlertSQL columns in my existing table.
How will be my update script?
My script for update is as below:
update dbo.F_ALERT
set AlertSQL= 'exec e_Report.dbo.FTX_FA_Aging_Report_sp '''FACloedAgingReport''
where AlertID=9330
Some how its not giving me expected result.
Thanks in Advance !!
Check your quote positioning. You need a pair of single quotes at either end of the quoted string, as well as the quotes for the whole query.
'exec ee_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReportSee'''
Currently you have three before and two after, it should be the other way around as per Gordon's answer.
See https://support.microsoft.com/en-us/kb/178070
You need more quotes and things:
update dbo.F_ALERT
set AlertSQL= 'exec e_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReport'''
where AlertID = 9330 ;
It is a bit confusing, but '''' is a string with a single quote. Two single quotes together are a single single quote. Hence:
'exec e_Report.dbo.FTX_FA_Aging_Report_sp ''FACloedAgingReport'''
^ starts a string
------------------------------------------^ two quotes are single quote in the string
--------------------------------------------------------------^ two quotes are single quote in the string and then one more to end the string itself

Select /*csv*/ in oracle set delimeter and enclose character

I want to use the /*csv*/ to set the output to csv in oracle. But I need to change the delimiter and enclosing character.
I don't want to insert a bunch of "||" in my query to resolve this.

How to escape single quotes in Sybase

I come from MySQL and the below query doesn't work in Sybase. How should I escape single quotes?
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
If working with Sybase, having got used to MySQL which more database users have experience you may soon discover you are unable to escape single quotes with backslash in.
So how do you escape quotes in Sybase? In fact, in Sybase SQL the single quote acts as the escape character.
See below for an example UPDATE statement in both “languages”:
MySQL
UPDATE Animals SET NAME = 'Dog\'s friends' WHERE uid = 12
Sybase
UPDATE Animals SET NAME = 'Dog''s friends' WHERE uid = 12
I’m not entirely sure this makes sense to me (especially as it looks like a double quote) but there you go!
You can create a custom function to escape quotes :
CREATE FUNCTION "ESCAPE_QUOTES"(in a_string long varchar)
returns long varchar
begin
return replace(a_string, '''', '''''');
end

How do I remove single quotes from a table in postgresql?

I searched around quite a bit, it would be great if someone could link me to a solution or answer my query.
The thing is I have a postgresql table that contains a lot of single quotes and I cant figure out how to get rid of them, because obviously this
update tablename set fieldname= NULL where fieldname=' ;
wont work.
Better use replace() for this:
UPDATE tbl SET col = replace(col, '''', '');
Much faster than regexp_replace() and it replaces "globally" - all occurrences of the search string. The previously accepted answer by #beny23 was wrong in this respect. It replaced first occurrences only, would have to be:
UPDATE tbl SET col = regexp_replace(col, '''', '', 'g');
Note the additional parameter 'g' for "globally". Read about string functions in the manual.
Aside: the canonical (and SQL standard) way to escape single quotes (') in string literals is to double them (''). Using Posix style escape sequences works, too, of course. Details:
Insert text with single quotes in PostgreSQL
update tablename set fieldname= NULL where fieldname='''' ;
or
update tablename set fieldname= NULL where fieldname=E'\'' ;
insert into table1(data) values ($$it's a string, it's got some single quotes$$)
Use $$ before and after the string. It will insert data.