Execute SQL Task issue

  • 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

  • REPLACE(Stage,'Closed Won','Awarded')

    Mack

  • 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.

  • Can ou post all of your query - also the column name is [stage] right?

    Mack

  • 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.[/url] Get your answers faster.

  • Hi Mack,

    I attached a screen shot from SSIS which shows the statement. Stage is the correc col. name.

  • 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

  • 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

  • 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.

  • 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

  • Hey Erik,

    I created a table #temp with one field. I inserted four rows in it. Then tried the replace statement as you did.

    CREATE TABLE #temp ( word VARCHAR(100))

    SELECT * FROM #temp

    --saat

    --bat

    --hoot

    --boot

    SELECT REPLACE(word,'oo','**') FROM #temp

    --saat

    --bat

    --h**t

    --b**t

    You must use the column name ( word in my table) in 1st expression, then the pattern (in singlequotes) in 2nd expression and the replace string pattern(in single quotes) in 3rd expression.

    Hope this helps !!!

    Regards,

    Suresh

  • Thank you and all who responded. I had to break away for a lenghty meeting and will being trying the solutions in a bit. I'll report back the results.

  • Hi,

    I was able to execute the following in Management studio successfully but was unable to replicate the results when using BIDS.

    Update dbo.mydatabase

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

    I tried the table solution but was not able to achieve the desired results.

  • I may be missing something here, but why not just

    update mydatabase

    set stage = 'Awarded' where stage = 'Closed Won'

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply