-2

So I'm supposed to take the last two digits from the phone number, and insert it into a new column in the same table.

I'm currently getting this error:

Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'Pass_id', table 'lunches.dbo.passenger'; column does not allow nulls. INSERT fails.
The statement has been terminated.

This is the query I'm using to get this error:

INSERT INTO dbo.passenger (age)
SELECT 
RIGHT(phone, 2)
FROM dbo.passenger
4

1 回答 1

4
UPDATE dbo.passenger
SET    age = Cast(Right(phone, 2) As tinyint)
WHERE  phone IS NOT NULL
AND    Right(phone, 2) NOT LIKE '%[^0-9]%'
于 2013-08-06T15:57:29.497 回答