views:

18

answers:

1
UPDATE CustomerPhone 
SET PhoneTypeID = 7, PhoneNumber = 999-444
WHERE CustomerID = 500 AND PhoneNumber = 9-1-1;

PhoneNumber is of type varchar(20) whereas PhoneTypeID and CustomerID are of type int. I'm running the above statement in SQL Server, it works fine.

I wonder how come it works? I thought any string value has to be put between '...'

+2  A: 

SQL Server will CAST or CONVERT the value that you pass it, when you specify a value that isn't of type that you expect.

i.e. Try: SELECT * FROM CustomerPhone WHERE PhoneTypeID = '7'

Here SQL Server will take your string '7' and try to convert to the appropriate type of int, smallint, tinyint (whatever appropriate).

p.campbell
SELECT * FROM CustomerPhone WHERE PhoneTypeID = '7'Worked fine!
peace