Link to home
Create AccountLog in
Avatar of mounty95
mounty95Flag for United States of America

asked on

SQL Syntax

I have a MS SQL table that holds data from several memo fields.  The data in the memo fields can contain apostrophes and double quotes.  How can I make it so that SQL accepts these?

Here is an example of hard coded values as an example:

insert into MDP_data (psc#,priority,fy,status_code,justification,staff_comments)
values
('1.0012','1','2016',
'B',
'Deferral of partial funding is recommended. Planning was approved in FY13 and partial funding was approved in FY14 and FY15. See worksheet for approved scope and funding details.',
'10/29 Comments: The LEA will bid in feb and start construction in April 2015.  DDs rec'd by DGS.  CDs are underway.  There maybe a delay in demolition.  There are several large alternates for this project.  MEMA issues are all worked out.  They would like to receive full funding for this project.')
Avatar of Aneesh
Aneesh
Flag of Canada image

for single quotes within the text, replace each of them with 2 single quotes when you are inserting data from within sql server management studio. from application you don't have to worry about this.
I don't think you need to worry about the double quotes
Avatar of mounty95

ASKER

My question is though, how do I replace the single quotes with a variable in an insert statement like the one in my example, but where instead of hard coded values, I have variable A, variable B, variable C, variable D, variable E, and variable F.
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Richard Obenchain
Richard Obenchain

A better option would be to create a stored procedure to update these fields and use parameters passed from the code rather than executing a SQL statement directly.  That will also eliminate SQL injection problems down the line.
Thanks for the grade.  Good luck with your project.  -Jim