Solved

Concatenate SQL Records with UPDATE

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help constructing a conditional update query 16 69
SQL Syntax 24 45
MIcrosoft SQL 2014 Database Copy Question 16 51
How to structure query with count aggregate 4 13
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…

856 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