Conversion failed when converting the varchar value 'Send' to data type bit.

X0r1 1 Reputation point
2021-04-21T14:17:39.187+00:00

In Sql Server Management Studio 15.0 cannot edit table with field name "Send" and data type bit

Error on edit another field :
Microsoft SQL Server Management Studio
No row was updated.

The data in row 1 was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: Conversion failed when converting the varchar value 'Send' to data type bit.

Correct the errors and retry or press ESC to cancel the change(s).

but if I change column name "Send" to "Send_" work successfully

90041-dbotest2-microsoft-sql-server-management-studio.png

90014-dbotest-microsoft-sql-server-management-studio.png

Example :
In table "test" I cannot edit row, but in table "test2" I can edit and insert data.

![CREATE TABLE [dbo].[test](  
 [id] [int] IDENTITY(1,1) NOT NULL,  
 [desc] [varchar](max) NOT NULL,  
 [Send] [bit] NOT NULL,  
 CONSTRAINT [PK_test] PRIMARY KEY CLUSTERED   
(  
 [id] ASC  
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]  
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]  
  
/*---------------------------------------------------------------------*/  
  
CREATE TABLE [dbo].[test2](  
 [id] [int] IDENTITY(1,1) NOT NULL,  
 [desc] [varchar](max) NOT NULL,  
 [Send_] [bit] NOT NULL,  
 CONSTRAINT [PK_test2] PRIMARY KEY CLUSTERED   
(  
 [id] ASC  
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]  
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]  
  
  
  
SQL Server Other
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-04-21T15:07:05.877+00:00

    I tested this and it appears to be a bug in SSMS. The issue, I believe, is that desc is a keyword in T-SQL and send is part of a larger statement.

    However it is actually inserting (twice in my case) but the UI is reporting the error. If you try to edit in the UI, let it error, cancel the edit, close the table and reopen it you might see it actually added it twice.

    You should report this as a bug to the SSMS team.

    1 person found this answer helpful.

  2. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2021-04-22T06:04:34.537+00:00

    Hi @X0r1 ,
    Thanks for your feedback. After some testing, I also encountered the same issue as you.
    Currently, you can use INSERT INTO statement to insert new records in a table and use UPDATE statement to update records. You also can right-click the Table->Script Table as-> INSERT To/UPDATE To to help you insert or update records.
    Sorry for the inconvenience.
    In addition, if you find any post in the thread is helpful, you could kindly accept it as answer. This would benefit the community, and encourage the community member to keep working on your issues.

    Best Regards,
    Amelia

    1 person found this answer helpful.
    0 comments No comments

  3. Michael Taylor 60,161 Reputation points
    2021-04-21T14:28:50.63+00:00

    You cannot store a text value in a bit column. The error is pretty obvious. But I'm really confused as to what actual value you're using. The column name is Send but you said the error says error converting 'Send' to bit. That would mean you are trying to set the Send column with the value Send which wouldn't work as it is a bit column. The only values you can put into a bit column is 0 or 1.


  4. Guoxiong 8,206 Reputation points
    2021-04-21T14:38:27.137+00:00

    AS cooldadtx mentioned, only values you can use for the bit column are 0 or 1 since you set the column NOT NULL. The error should not depend on the column name. For example, if you run the following query, you will get the error:

    Msg 245, Level 16, State 1, Line 7
    Conversion failed when converting the varchar value 'Send' to data type bit.

    DECLARE @Test TABLE (
     [Id] int IDENTITY(1,1) NOT NULL,
     [Desc] varchar(max) NOT NULL,
     [Send_] bit NOT NULL
    );
    
    INSERT INTO @Test
    SELECT 'Test1', 'Send';
    

  5. Viorel 122.6K Reputation points
    2021-04-21T14:45:10.133+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.