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)
 convert varchar to a value of type int

Author  Topic 

young555
Starting Member

9 Posts

Posted - 2009-05-01 : 14:50:14
I get the following error message when I’m running my query.
I know what the problem is and I kind of know how to write the code, but I keep getting a syntax error.
Can someone please advise me on how to write this bit of code. I want the columns of type int to have the test ‘value’ written in them.
The error I get is
Msg 245, Level 16, State 1, Line 58Syntax error converting the varchar value 'value' to a column of data type int.

My code is:
insert into result (int, Status, Sum, CN, datetime, D, int, BillableTo, RB, datetime, int, IA, ITRNotes) values (@rowCounter, 'value', 'value', ' value', ' value', 'value', 'value', 'value', 'value', 'value', 'value', 'value', 'value')

I have written which values are int so its easy for you to know which one it is. I know I should use maybe the following code but I don’t know how to apply it.

convert(varchar(10),ID)

please help
thanks

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-05-01 : 14:58:41
You can't insert strings into INT fields, int fields only take integers, you can't even insert '5,000' into an int field since that comma makes it a string. Try -9999999, or some other dummy value.

Jim
Go to Top of Page

young555
Starting Member

9 Posts

Posted - 2009-05-02 : 03:47:06
thank you for the reply,
i will try it out and let you know how i go
Go to Top of Page

young555
Starting Member

9 Posts

Posted - 2009-05-05 : 16:29:04
your advice was spot on,
thanks, my query works now
Go to Top of Page
   

- Advertisement -