Problem in inserting values to a table in SQL

July 27, 2009 at 23:22:46
Specs: Windows XP, Dual core/ 2GB
I have created a table in SQL Server as-

create table weatherreport
(places varchar(20),
cdate datetime,
maxm int,
minm int,
vdescription varchar(40))

Then I tried to insert the corresponding values as-

insert weatherreport
values('guwahati','07-01-09',31.4,26.7,'cloudy sky with one or two spells of rain or thunderstorms')

But I got a message as-
"String or binary data would be truncated.
The statement has been terminated."

Then I tried the following-

insert weatherreport(places,cdate,maxm, minm,vdescription)
values('guwahati','07-01-09',31.4,26.7,'cloudy sky with one or two spells of rain or thunderstorms')

But I got the same message. I couldn't find out my mistake. Please help me on this.


See More: Problem in inserting values to a table in SQL

Report •


#1
July 28, 2009 at 08:24:41
I am not a SQL server guy, but the problem is most likely the datetime. Most datetimes are formatted like:

2009-07-21

If you still have a problem, try adding a time:

2009-07-21 13:42

If you still have a problem, read the manual on SQL Server datetime.


Report •

#2
July 29, 2009 at 05:14:53
Have a look at the dates thing, as above.

Also, you're inserting decimal values in a column which you've said is an integer.

maxm and minm are both created as integers, then you're trying to drop in 31.4 and 26.7

In mysql, you'd create the table with decimal(x,y) (I *think* it's NUMERIC(x,y) in MS SQL) where x is the number of characters in the full number (including decimal places), and y is the number of characters that should come after the decimal point.


Report •

Related Solutions


Ask Question