Solved

Concatenate SQL Records with UPDATE

Posted on 2007-12-03
4
3,913 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

724 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