请教SQL语句错得莫名其妙

OdellaChen 2004-05-07 01:37:16
insert into sample(entry_ID,
Trade_co,
D_Date,
process_mark,
A,B,C)
select 1,1,2004-3-37,'1Afeg','a1','b1','c1'
union all select 2,2,2004-3-24,'1Bdfg','a1','b2','c1'
union all select 3,1,2004-4-21,'1EFDS','a2','b4','c2'
union all select 4,5,2004-2-23,'1Afeggg','a3','b3','c2'

服务器: 消息 8152,级别 16,状态 9,行 1
将截断字符串或二进制数据。
语句已终止。


是什么原因呢?
...全文
45 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
谢谢大家
wisdom369 2004-05-07
  • 打赏
  • 举报
回复
原因是用你的建表sql创建的表的process_mark,A,B,C等几个varchar型字段的长度都是1,而在你的insert语句中这几个字段对应的值的长度都超过了1,所以会出现"将截断字符串或二进制数据。"的错误提示.
如果要获得正确结果,则应该在建表sql中对varchar型字段设置相应的字段长度,如:
create table sample(entry_ID int,
Trade_co int,
D_Date datetime,
process_mark varchar(50),
A varchar(50),B varchar(50),C varchar(50),
p_trade_co_his int,p_fawl_his int)
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
up~
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
肯定存在,我都可以打开的
zheninchangjiang 2004-05-07
  • 打赏
  • 举报
回复
那就是不存在所写的列
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
不会啊,@A char(10),
@B char(10),
@C char(10),
A,B,C都只有两个字符的说

呜~~~~~~~
linsunshine 2004-05-07
  • 打赏
  • 举报
回复
数据超长,缩小value长度或者增加字段的定义长度
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
又说我列名无效是怎么回事?

CREATE Procedure s1
as
declare @Trade_co char(10),
@D_Date datetime,
@A char(10),
@B char(10),
@C char(10),
@mynum int,
@allnum int,
@fmynum int,
@fallnum int


declare samp_cursor cursor for
select Trade_co,D_Date,A,B,C
From sample

open samp_cursor
fetch next from samp_cursor
into @Trade_co,
@D_Date,
@A,
@B,
@C
while @@FETCH_STATUS = 0
begin

select * into kk from IM_ENTRY_HEAD where Trade_co=@Trade_co and D_Date<@D_Date and left(process_mark,2)='1A'

select @mynum=count(*) from kk where A=@a and B=@b and C=@c

select @allnum=count(*) from kk

update sample set p_trade_co_his=@mynum/@allnum


select * into jj from IM_ENTRY_HEAD where D_Date<@D_Date and left(process_mark,2)='1B'
select @fmynum=count(*) from jj where A=@a and B=@b and C=@c

select @fallnum=count(*) from jj

update sample set p_fawl_his=@fmynum/@fallnum

fetch next from samp_cursor
into @Trade_co,
@D_Date,
@A,
@B,
@C
end
CLOSE samp_cursor
DEALLOCATE samp_cursor

go


服务器: 消息 207,级别 16,状态 3,过程 s1,行 30
列名 'A' 无效。
服务器: 消息 207,级别 16,状态 1,过程 s1,行 30
列名 'B' 无效。
服务器: 消息 207,级别 16,状态 1,过程 s1,行 30
列名 'C' 无效。
bflovesnow 2004-05-07
  • 打赏
  • 举报
回复
1、varchar加上宽度

2、日期加上''
zheninchangjiang 2004-05-07
  • 打赏
  • 举报
回复
表定义时出的问题,varchar 也要指定长度作为列最大宽度,否则默认为1,这样就造成列宽不够
welyngj 2004-05-07
  • 打赏
  • 举报
回复
insert into sample(entry_ID,
Trade_co,
D_Date,
process_mark,
A,B,C)
select 1,1,'2004-3-37','1Afeg','a1','b1','c1'
union all select 2,2,'2004-3-24','1Bdfg','a1','b2','c1'
union all select 3,1,'2004-4-21','1EFDS','a2','b4','c2'
union all select 4,5,'2004-2-23','1Afeggg','a3','b3','c2'
OdellaChen 2004-05-07
  • 打赏
  • 举报
回复
表定义是这样的
create table sample(entry_ID int,
Trade_co int,
D_Date datetime,
process_mark varchar,
A varchar,B varchar,C varchar,
p_trade_co_his int,p_fawl_his int)

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧