Solved

Migration to MSSQL - Concatenation in Update Statement

Posted on 2012-04-05
3
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

617 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