Solved

Why is string passed from Access VBA to SQL Server Stored Procedure losing the chr(13) from vbcrlf

Posted on 2008-06-10
4
433 Views
Last Modified: 2012-05-05
I have simple stored procedure to create a new customer record if one with a matching name and postcode does not automatically exist. The procedure is called from Microsoft Access using VBA. The address is a string with the lines seperated by vbcrlf.

When the procedure is called from Access the address ends up with lines seperated only by char(10). The char(13) part of the vbcrlf is lost somehow. If I test the procedure from SQL Server management studio it works fine.

Any ideas on how I can get the full newline control sequence into the database (I could add a few lines to insert a char(13) in front of any orphaned char(10) but that is not elegant!)
ALTER PROCEDURE [dbo].[CUSTOMERINSERT] @NAME VARCHAR(50),@ADDRESS VARCHAR(2000),@POSTCODE VARCHAR(50),@ID INT OUTPUT

AS

BEGIN

	SELECT @ID=ID FROM CUSTOMER WHERE [NAME]=@NAME AND POSTCODE=@POSTCODE

	IF @ID IS NULL

		BEGIN

			INSERT INTO CUSTOMER ([NAME],ADDRESS,POSTCODE) VALUES (@NAME,@ADDRESS,@POSTCODE)

			SET @ID=SCOPE_IDENTITY()

		END

	IF @ID IS NULL

		SET @ID=0

END

Open in new window

0
Comment
Question by:BOIT
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21752331
I believe that appearances can be deceptive.

when you use vbcrlf to concatenate strings, and then pass them to SQL via a stored procedure, I think it will just use SQL's new line character (char 10), this will however appear to be correct when testing the procdure in the management studio.

Try using the character codes when calling the stored proc

ie char(13) & char(10) &
instead of vbcrlf &
0
 

Author Comment

by:BOIT
ID: 21757785
I tried concatenating the string using chr(13) & chr(10) instead of vbcrlf but it makes no difference.

I have just realised that I have made a mistake in outlining this question. The actual technology I am using for this bit of the project is a web service written in vb in asp.net. Therefore the stored procedure is being called from iis on the target host.

As this changes the title of the question and quite possibly the solution I am going to repost the question and request a close on this one.

Thank you for your comment Chrisedebo and I will welcome your input on the reposted question if possible.

0
 
LVL 7

Expert Comment

by:Chrisedebo
ID: 21758231
Sure, if you could post a link to it here then I can find it easier :o)
0
 

Accepted Solution

by:
BOIT earned 0 total points
ID: 21758339
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now