Computing.Net > Forums > Database > Problem in inserting values to a table in SQL

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Problem in inserting values to a table in SQL

Reply to Message Icon

Name: Daisy B.
Date: July 27, 2009 at 23:22:46 Pacific
OS: Windows XP
CPU/Ram: Dual core/ 2GB
Subcategory: MS SQL Server
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 28, 2009 at 08:24:41 Pacific
Reply:

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.


0

Response Number 2
Name: jon_k
Date: July 29, 2009 at 05:14:53 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Problem in inserting values to a table in SQL

sql to list related obj of a table www.computing.net/answers/dbase/sql-to-list-related-obj-of-a-table/258.html

Inserting value in an identity column www.computing.net/answers/dbase/inserting-value-in-an-identity-column/661.html

Combine 2 reports in SQL www.computing.net/answers/dbase/combine-2-reports-in-sql/378.html