stored procedure - create t-sql to replace the dreaded apostrophe

I have to create a stored procedure where I pass in 4 variables, each with different lengths, and I need to check to see if there is an apostrophe that I replace it with a double quote. I then need to insert the record into the table. If everything goes OK, I'd like to pass back a variable to my VB program indicating that the INSERT worked fine.

Could someone throw together the snippet of code on what would be required to put this all together and please a short comment on each step of what is going on.

Fairly new to creating stored procedures. Have always using the INSERT, UPDATE and DELETE in my VB code using ADO and am trying to convert everything to stored procedures.

Thanks in advance.
LVL 13
Who is Participating?
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
a sample code for the procedure attached.
note: if the procedure execution succeeded, the insert completed successfully. if any error was raised, the insert failed (and rolled back).

CREATE PROCEDURE proc_do_insert
 (@pk int
 ,@data_1 varchar(100)
 ,@data_2 varchar(200)
 ,@data_3 datetime
  INSERT INTO yourtable (pk, col1, col2, col3)
  VALUES (@pk, @data_1, @data_2, @data_3) 

Open in new window

Guy Hengel [angelIII / a3]Billing EngineerCommented:
unless you use dynamic sql, you don't need to check for quotes in the parameter variables.
Ashish PatelConnect With a Mentor Commented:
So, just create a stored procedure like the code snippet, and pass your parameters as they are, and you will not have to worry about double quotes when you are working with stored procedure. Single quote wont give any issue when using SP. Look at the insert SP code snippet
Create Procedure InsertValues
@EmpID int,
@Name varchar(50),
@Firstname varchar(100)
       Insert Into TableName (EmpID, Name, FirstName) Values (@Empid, @Name, @FirstName)

Open in new window

Guy Hengel [angelIII / a3]Billing EngineerCommented:
note: the corresponding vb will probably be using ADO, in which case you check out the ADODB.Command (vb6) resp SqlCommand ( with object, and using the ADODB.Parameter (vb6) / SqlParameter ( + object to be able to work without the quotes problems...
All Courses

From novice to tech pro — start learning today.