[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Concatenate SQL Records with UPDATE

Posted on 2007-12-03
4
Medium Priority
?
3,919 Views
Last Modified: 2008-02-01
Hello, I'm using SQL Server 2005 and I want to update the name in over 18000 records

I want it to be:  name (size) instead of name:

example:
Vitamin A (60 Caps)
right now its:
Vitamin A

Update b
Set b.Name = b.Name' ('a.Size)'
From Product b, newproducturlinfo a
WHERE b.SKU LIKE a.UPC AND b.ProductID = 32167

I keep getting this:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ' ('.

I'm using ProductID = 32167 because I don't want to affect more then 1 record if it goes wrong.  Any info will help.  Thanks
0
Comment
Question by:smoothcat11
[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
4 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 20400591
Hi,

Your concatenation was wrong.

And changed the join syntax

HTH
  David
update b
set b.Name = b.Name + ' (' + a.Size + ')'
from dbo.Product b
inner join dbo.newproducturlinfo a
	on b.SKU like a.UPC
where
	b.ProductID = 32167

Open in new window

0
 

Author Comment

by:smoothcat11
ID: 20400603
Msg 402, Level 16, State 1, Line 1
The data types nvarchar and ntext are incompatible in the add operator.

Just got this.

They are ntext
0
 
LVL 35

Accepted Solution

by:
David Todd earned 2000 total points
ID: 20400609
Hi,

Can you post the table structure(s) and some sample data.

Any reason why these fields are ntext instead of say nvarchar( max )?

Cheers
  David
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20400634
update b
set b.Name = b.Name + ' (' + cast(a.Size as nvarchar)  + ')'
from dbo.Product b
inner join dbo.newproducturlinfo a
        on b.SKU like a.UPC
where
        b.ProductID = 32167
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 shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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