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
samic400Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
unless you use dynamic sql, you don't need to check for quotes in the parameter variables.
0
Ashish PatelCommented:
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)
Begin
       Insert Into TableName (EmpID, Name, FirstName) Values (@Empid, @Name, @FirstName)
End

Open in new window

0
Guy Hengel [angelIII / a3]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
 )
AS
BEGIN
  INSERT INTO yourtable (pk, col1, col2, col3)
  VALUES (@pk, @data_1, @data_2, @data_3) 
END

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 (vb.net with ado.net) object, and using the ADODB.Parameter (vb6) / SqlParameter (vb.net + ado.net) object to be able to work without the quotes problems...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.