SQL insert error Argument data type text is invalid for argument 1 of replace function

Posted on 2009-02-17
Last Modified: 2012-05-06
I am running a query on my database to insert values into a table and I keep getting the following error 'Argument data type text is invalid for argument 1 of replace function.'

The query is not using a replace function so I have no idea what is causing the problem. Here's a simple form of the query that fails.

INSERT INTO table_name (field1, field2, field3, field4) VALUES ('test', 'test','test', 'test')  
The table field types are: int (identity), varchar, text, varchar, varchar
Question by:charlesqa
    LVL 14

    Expert Comment

    the data type for the first field is not a char.

    INSERT INTO table_name (field1, field2, field3, field4) VALUES (2, 'test','test', 'test')  


    Author Comment

    I am confused. The first field in the table is the id column which is an identity field and should be auto incrementing. Which is why the insert statement only includes the varchar/text field entries. I am misunderstanding your explanation?

    Author Comment

    Sorry just to clarify the field types:
    field1 = varchar
    field2 = text
    field3 = varchar
    field4 = varchar
    The int field is the primary key and an identity column that is not specified in the INSERT statement.
    LVL 14

    Accepted Solution

    do you have a trigger on this table?

    Author Comment

    That was it. This is inherited code and for the life of me I could not figure out why it was failing. There was a trigger that did a REPLACE function which of course does not work on the text datatype.
    Thanks for the insight.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Viewers will learn how the fundamental information of how to create a table.

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now