Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Conversion failed varchar to small int

Author  Topic 

rob41
Yak Posting Veteran

67 Posts

Posted - 2010-10-03 : 17:23:18
I am getting the following errors when I try and run the query below:

Conversion failed when converting the varchar value 'EDI' to data type smallint. [SQLSTATE 22018] (Error 245). The step failed.

All I'm trying to do with this query is change values that are either 1 or 0 to EDI, or MAN
UPDATE [Ships]
SET [Ships].[FrctRte] = 'EDI'
FROM [Ships]
WHERE [FrctRte] = '1'

UPDATE [Ships]
SET [Ships].[FrctRte] = 'MAN'
FROM [Ships]
WHERE [FrctRte] = '0'

UPDATE [Ships]
SET [Ships].[FrctRte] = 'MAN'
FROM [Ships]
WHERE [Load Id] LIKE 'I%'

UPDATE [Ships]
SET [Order Type] = [FrctRte]
FROM [Ships]
WHERE [Order Type] IS NULL

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-03 : 17:38:21
Looks like FrctRte is of datatype smallint.
A smallint cannot store characters.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

warchild2010
Starting Member

1 Post

Posted - 2010-10-03 : 18:03:39
Before you will be able to change the values of the column to EDI or MAN you will first need to change the column to that of datatype varchar. As of right now as the previous posting showed was that you are currently attempting to load character values into a column which will only allow numeric values. If you change the datatype of the column and rerun your script your problem should go away.
Go to Top of Page

ricky_1605
Starting Member

30 Posts

Posted - 2010-10-04 : 07:45:58
Change the datatype of column [Frcrte] to varchar and it will solve the problem.

Nipun Chawla
Go to Top of Page

rob41
Yak Posting Veteran

67 Posts

Posted - 2010-10-04 : 18:23:18
Thanks all of the suggestions helped me fix the problem
Go to Top of Page
   

- Advertisement -