How this below insert query can be modified or escape single quote in SQL Server:
INSERT INTO <tblname> (title,desc)
VALUES
('Hen's Body','It's just best combination')
This query not run in SQL Server. I need similer solution to MySQL (like using backslash)as it is
INSERT INTO <tblname> (title,desc)
VALUES('Hen\'s Body','It\'s just best combination')
Regards
Double up the single quotes to escape them:
INSERT INTO ( title, description )
VALUES ( 'Hen''s Body', 'It''s just best combination' )
Related
There is a single quote in insert script. Like 'JOHN'S' , Is there any other way to insert it except using Concat and two times single quote in Sybase.
Like 'JOHN''S'.
As I am able to handle it in oracle like q'(JOHN'S)'. Is there any function to handle this in sybase.
So I seem to be forced to use MS Access as a SQL Server client.
For whatever reason, this just won't execute:
INSERT INTO l9990064_INF_PATH (DATA_PATH)
VALUES ("/OlifeRequest/RequestType")
SELECT DATA_PATH, "/OlifeRequest/RequestType"
FROM l9990064_INF_PATH
WHERE DATA_PATH NOT IN
(SELECT DISTINCT DATA_PATH
FROM l9990064_INF_PATH
WHERE DATA_PATH="/OlifeRequest/RequestType");
Basically the query attempts to insert a field in table if it doesn't already exist in that table.
The error I get is:
Missing semicolon (;) at end of SQL statement.
Clearly this is not the case, there is in fact a semicolon at the very end.
It appears to be a valid query so I'm wondering what I have to do here? Thanks!
INSERT INTO l9990064_INF_PATH (DATA_PATH)
VALUES ('/OlifeRequest/RequestType'); --<-- Single Quotes
SELECT DATA_PATH, '/OlifeRequest/RequestType' --<-- Single Quotes
FROM l9990064_INF_PATH
WHERE DATA_PATH <> '/OlifeRequest/RequestType'; --<-- Single Quotes
Also there is no need to use NOT IN operator since it is checking the value in the same table it is selecting from.
Or if you were trying to insert data from a SELECT statement , it would be something like ....
INSERT INTO l9990064_INF_PATH (DATA_PATH, Other_Column_Name)
SELECT DATA_PATH, '/OlifeRequest/RequestType'
FROM l9990064_INF_PATH
WHERE DATA_PATH <> '/OlifeRequest/RequestType';
I didn't know this at first, but it appears the queries I was using would work in SQL server but Access was only allowing Access queries or some shit. So even though Access was acting as a SQL server client, it wasn't really allowing me to use SQL server queries.
I went through the pain of getting SQL Server Management Studio as the client through the painful procurement at my company and I couldn't think of a better solution, do not use Access as a SQL Server client kids...
I tried to insert korean text into my ms sql server table, but it seems not working properly because all characters are broken like "????" as following:
The type of column is nvarchar, and I query as follow to put the data: insert into mytable values('텍스트'). And the collation is SQL_Latin1_General_CP1_CI_AS, but I wonder if the collation is the problem.
Please help me to find solution
Try this
While working with nvarchar datatype always use N'...'
insert into mytable values(N'텍스트');
This sqlfiddle example shows the difference if you don't use N'...'.
http://sqlfiddle.com/#!6/fab9a/1
I am trying to update a row in the my SQL Server 2008 R2 database.
The value of the particular column is of type String.
The current values in my database is of the form: NMA.
But it should be N'MA.
My query is:
UPDATE mymodifiedtable
SET FirstName = 'N'MA'
WHERE receiptNo = '45047603'
This is not working for me after googling it.
Pls advice.
I would also like a link where I can learn more on this type of escape characters in SQL Server.
You can use the quote character to escape quotes. Try SET FirstName = 'N''MA'
Within SQL Server 2005 T-SQL, I would really like to pull these columns:
constraint_type, constraint_name, and constraint_keys
from the output of sp_HelpConstraint. However it returns 3 result sets (2 if you pass in 'nomsg'), so you can't do this to capture it:
CREATE TABLE #Constraints
(
...
)
INSERT INTO #Constraints
(... )
EXECUTE sp_HelpConstraint 'TableName', 'nomsg'
The only ways I can think of doing this are not good ones:
just copy the code I need from sp_HelpConstraint
"fix" sp_HelpConstraint so 'nomsg' removes the last result set too
any ideas?
Hopefully, you're on SQL 2005+
sys.default_constraints etc to allow standard SELECT
Otherwise, you can use Information Schema Views on SQL 2000 +