SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Execute SQL Task issue


Execute SQL Task issue

Author
Message
erik.nelke 98967
erik.nelke 98967
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
I am trying to use the REPLACE function with no success. I have a Column name "Stage". In the column I need to find the value "Closed Won" and replace it with the value of "Awarded".

I've tried variations of this statement but this is the jist of it.

REPLACE("Closed Won","Closed Won","Awarded")

It stops with the following erorr which has proven to be little help.

[Execute SQL Task] Error: Executing the query "REPLACE("Closed Won","Closed Won","Awarded")" failed with the following error: "Incorrect syntax near 'Closed Won'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Thank you for your help.

Erik
Mackers
Mackers
Say Hey Kid
Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)

Group: General Forum Members
Points: 695 Visits: 499
REPLACE(Stage,'Closed Won','Awarded')

Mack
erik.nelke 98967
erik.nelke 98967
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
Hi Mack,

Thank you for the reponse. I used the statement and it returned the following.

[Execute SQL Task] Error: Executing the query "REPLACE(Stage,'Closed Won','Awarded')" failed with the following error: "Incorrect syntax near 'Stage'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Mackers
Mackers
Say Hey Kid
Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)

Group: General Forum Members
Points: 695 Visits: 499
Can ou post all of your query - also the column name is [stage] right?

Mack
calvo
calvo
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3370 Visits: 4018
REPLACE ( string_expression , string_pattern , string_replacement )


SELECT REPLACE ( 'closed won' , 'closed won', 'award')


the string_expression can be a column, variable, or string.

______________________________________________________________________________________________
Forum posting etiquette. Get your answers faster.
erik.nelke 98967
erik.nelke 98967
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
Hi Mack,

I attached a screen shot from SSIS which shows the statement. Stage is the correc col. name.
Attachments
SSIS screen shot.docx (16 views, 93.00 KB)
Mackers
Mackers
Say Hey Kid
Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)

Group: General Forum Members
Points: 695 Visits: 499
Your SQL statement needs to be a proper statement ie

Select REPLACE(Stage,'Closed Won','Awarded')
from your_table

What are you trying to do? An update? Assign a variable?

Mack
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35397 Visits: 16683
The REPLACE statement doesn't update the table for you. All it does is return the first expression but with any occurrence of the second expression replaced by the third expression. If you want to update your table then you need to put your REPLACE statement into an UPDATE statement.

John
erik.nelke 98967
erik.nelke 98967
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
Hi,

I was able to get it to run with out error using calvo's statement and also Mack's statement. The only issue is that the value of Closed Won is not being replaced with Awarded.
Mackers
Mackers
Say Hey Kid
Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)Say Hey Kid (695 reputation)

Group: General Forum Members
Points: 695 Visits: 499
What do you want the SQL task to do? Update the column?

If so the SQL needs to be

Update table_name
Set stage = REPLACE(Stage,'Closed Won','Awarded')

Mack
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search