views:

35

answers:

2

I'm getting an error with what should be a simple query to insert data. I've done searching, but for the life of me, I cant figure out whats happening. Here's my SQL:

IF OBJECT_ID('settings') IS NOT NULL
DROP TABLE [settings]
CREATE TABLE [settings] (
    [id] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,   
    [tenant_id] [bigint] NOT NULL, 
    [name] [varchar](32) NOT NULL, 
    [value] [varchar](255) NOT NULL
)

INSERT INTO settings 
       (name, value, tenant_id)
       VALUES
       ('from_email' , '', 1),
       ('dash_rss', '', 1),
       ('theme', '', 1),
       ('version', '0.84', 1),
       ('iphone_theme', '', 1),
       ('enable_sandbox_number', 1, 1),
       ('twilio_endpoint', 'https://api.twilio.com/2008-08-01', 1);

And the error I get is: Conversion failed when converting the varchar value '0.84' to data type int.

Why is it trying to convert this to into when the column is varchar?

+1  A: 

I wonder if SQL Server is trying to outsmart you here. I noticed that your 'enable_sandbox_number' row includes an integer for the second parameter. Maybe SQL Server is converting to int because of that. Can you change 1 to '1' in that row?

bobs
You're a genius. That fixed the issue. Thanks!
Allen
A: 

Interesting that the 1 in ('enable_sandbox_number', 1, 1) is not quoted. Presumably it works okay. What happens if you try 0.84 unquoted?

Leo