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
435 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

770 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