The script I am trying is:
update tableQ
set columnA = 'value' columnA
where columnB equals (Numeric value)
The problem is that SQL says there is incorrect syntax near the keyword 'where'
I want to replace value 'This is a important document' with 'Top Dog - This is a important document' but only where the itemvalue = '12456'
Using MS Sql 2012
Any help appreciated
Add value at beginning of string but only on some rows
-
- 4StarLounger
- Posts: 504
- Joined: 23 Jul 2010, 18:36
- Location: Westlake, OHIO
Add value at beginning of string but only on some rows
Who will you Inspire today?
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Add value at beginning of string but only on some rows
Try
(Don't use quotes around numeric values)
Code: Select all
UPDATE [tableQ]
SET [columnA] = 'Top Dog - ' & [columnA]
WHERE [columnB] = 12345
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 504
- Joined: 23 Jul 2010, 18:36
- Location: Westlake, OHIO
Re: Add value at beginning of string but only on some rows
Thanks Hans
I receive "Incorrect Syntax near '&'"
This is the exact text that I used:
Update [hsi].[itemdata]
set [itemname] = 'A_UNDO_A - ', & [itemname]
where [itemnum] = 6684
and without the & I receive "Incorrect Syntax near 'where'"
Once I get this working I will be replacing the where statement with:
where [itemnum] in (around 242 numeric values, commas in between each of them)
I receive "Incorrect Syntax near '&'"
This is the exact text that I used:
Update [hsi].[itemdata]
set [itemname] = 'A_UNDO_A - ', & [itemname]
where [itemnum] = 6684
and without the & I receive "Incorrect Syntax near 'where'"
Once I get this working I will be replacing the where statement with:
where [itemnum] in (around 242 numeric values, commas in between each of them)
Who will you Inspire today?
-
- Administrator
- Posts: 78493
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Add value at beginning of string but only on some rows
Don't use a comma between the string and &:
Code: Select all
set [itemname] = 'A_UNDO_A - ' & [itemname]
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 504
- Joined: 23 Jul 2010, 18:36
- Location: Westlake, OHIO
Re: Add value at beginning of string but only on some rows
Thanks Hans!
It all works now.
It all works now.
Who will you Inspire today?