May 24, 2011 at 2:29 pm
yes - is the syntax different? I was under the impression it is the same...
May 24, 2011 at 2:30 pm
vradul (5/24/2011)
yes - is the syntax different? I was under the impression it is the same...
Some syntax is, but each product has certain things that are particular to that version of SQL.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 24, 2011 at 2:32 pm
vradul (5/24/2011)
I copied/pasted Lutz's query, adding * FROM 'table' to the SELECT...
DECLARE @x VARCHAR(50)
SET @x='Maryland<h2></h2>'
SELECT * FROM 'table' '<h2>'+ REPLACE(@x,'<h2></h2>','</h2>')
WHERE @x LIKE '%<h2></h2>'
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @x VARCHAR(50) SET @x='Maryland<h2></h2>' SELECT * FROM 'table' '<h2>'' at line 1
Your syntax is incorrect as the message states. The modification you made to the table creates the wrong syntax.
try this.
DECLARE @x VARCHAR(50)
SET @x='Maryland<h2></h2>'
SELECT * , '<h2>'+ REPLACE(@x,'<h2></h2>','</h2>') --move the from table from this line and added a comma after the *
FROM 'table' --move the from table to this line.
WHERE @x LIKE '%<h2></h2>'
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 24, 2011 at 2:39 pm
Thanks....
DECLARE @x VARCHAR(50)
SET @x='Maryland<h2></h2>'
SELECT * , '<h2>'+ REPLACE(@x,'<h2></h2>','</h2>')
FROM 'node_revisions'
WHERE @x LIKE '%<h2></h2>'
gives me syntax error still...
May 24, 2011 at 2:49 pm
remove the quotes from around your table name. Also, replace the variable in the replace statement with the column name from the table.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
May 24, 2011 at 2:50 pm
Did you realize the @x actually is a variable and not a column name?
Since we still don't know anything about your table structure we can't provide the correct (SQL Server) query. The fact that it is MySQL and not SQL Server doesn't help either. It might have helped if you would have mentioned it up front. But that's water down the river...
As a side note: a quick google search for REPLACE and MySQL seems to indicate that the functionality is different between the two database systems.
You might get more help on a MySQL forum, I'd say.
May 24, 2011 at 11:09 pm
vradul (5/24/2011)
I have a table named “table” containing a few hundred rows with a field named "teaser" that contains various text strings, among which are 50 rows with “teaser” containing the following:Maryland<h2></h2>
Maine<h2></h2>
Louisiana<h2></h2>
Kentucky<h2></h2>
Kansas<h2></h2>
Iowa<h2></h2>
...and so on...
I need a query to target those 50 rows to rewrite "teaser" like this in only those 50 rows:
<h2>Maryland</h2>
<h2>Maine</h2>
<h2>Louisiana</h2>
<h2>Kentucky</h2>
<h2>Kansas</h2>
<h2>Iowa</h2>
...and so on...
while leaving all other rows unchanged...
This can be done quite simply using REPLACE, a single concatenation, and a WHERE clause with a LIKE. Give it a try. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
May 25, 2011 at 4:52 am
solved for mysql with:
UPDATE mytable SET field=CONCAT('<h2>' , REPLACE(field,'<h2></h2>','</h2>'))
WHERE field LIKE '%<h2></h2>'
................
for sql this might work:
UPDATE mytable SET field=('<h2>' + REPLACE(field,'<h2></h2>','</h2>'))
WHERE field LIKE '%<h2></h2>'
Thanks for the help, guys!
May 25, 2011 at 5:59 am
Jeff Moden (5/24/2011)
This can be done quite simply using REPLACE, a single concatenation, and a WHERE clause with a LIKE. Give it a try. 😉
How embarrassing. I "missed" the other dozen or so posts after the original. I should stay in bed today. My apologies... :blush:
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 16 through 23 (of 23 total)
You must be logged in to reply to this topic. Login to reply