Solved

Migration to MSSQL - Concatenation in Update Statement

Posted on 2012-04-05
3
351 Views
Last Modified: 2012-04-10
I am migrating a database from access to MSSQL, and updating the website coding as I go. I had an update statement as follows:

UPDATE Customers SET cCredit = cCredit+"&Request.form("credit")&", cCreditNotes = '"&DATE()&"-"&Request.form("credit")&"-"&why&";"&cCreditNotes WHERE cId = "& Request.form("cust") &"

Open in new window


The update of cCreditNotes is supposed to add the entered values to the beginning of the existing data for that field. However, I get the following error:

The data types varchar and nvarchar(max) are incompatible in the '&' operator.

Open in new window


How can I achieve the same result as I had with Access in MSSQL?

Thank you
0
Comment
Question by:stressfreewebs
  • 2
3 Comments
 
LVL 2

Assisted Solution

by:davidi1
davidi1 earned 500 total points
ID: 37810414
have u tried using + instead of &?
0
 

Accepted Solution

by:
stressfreewebs earned 0 total points
ID: 37810457
Hi David,

I tried +, but found it didn't work when the value in the column was null.

However, I've got around that by repeating the same statement twice, once with a where xxx is null, and once with a where xxx is not null. The null one doesn't use +, the is not null one does.

This seems to do the trick, so thanks for the pointer to using the + sign

Dan
0
 

Author Closing Comment

by:stressfreewebs
ID: 37826737
Thanks to the pointer I was able to work a full solution
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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.

685 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