如果使用TEXTPTR函数和UPDATETEXT函数存储image类型数据?

tonysnss 2003-12-05 01:11:24
以下是我的写法,但是要报以下错误:
实时错误'-2147217900 (80040e14)'
向UpdateText函数传递了Null textptr(text,ntext或image指针).

----------------------------------------------
CREATE PROCEDURE YGTPSAVE
@ygtp image
as
DECLARE @ptrval binary(16)
SELECT top 1 @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode='E001'
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
GO
...全文
280 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
updatetext是用来在原有的数据上追加,替换用的.
你的情况根本不需要.

上面的存储还多了个一变量定义,将它也删除掉吧.
DECLARE @ptrval binary(16) --这句是多余的.
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
是可以直接用update.

你这一问我才发现,你只需要用最新的数据替换旧的数据.可以直接写成.


CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if exists(select 1 from tableEmployee where EmpCode=@ygbh)
update tableEmployee set EmpPhoto=@ygtp where EmpCode=@ygbh
else
insert into tableEmployee(EmpCode,EmpPhoto) values(@ygbh,@ygtp)
GO
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
行了,邹建大哥太感谢了,不过我最后想问一下

if @ptrval is null
update tableEmployee set EmpPhoto=@ygtp where EmpCode=@ygbh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
你这样写是不是直接用update存储图片,图片可以用update存储吗?
如果可以我们为什么要用UPDATETEXT
else
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
--是你的表中数据不规范
--可以这样改进
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if exists(select 1 from tableEmployee where EmpCode=@ygbh)
begin
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
if @ptrval is null
update tableEmployee set EmpPhoto=@ygtp where EmpCode=@ygbh
else
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
end
else
insert into tableEmployee(EmpCode,EmpPhoto) values(@ygbh,@ygtp)
GO
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
邹建,这是你的代码我运行也错误

--可以这样改进
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if not exists(select 1 from tableEmployee where EmpCode=@ygbh)
insert into tableEmployee(EmpCode,EmpPhoto) values(@ygbh,@ygtp)
else
begin
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
end
GO

exec ygtpsave 0x8989,'E002'


服务器: 消息 7133,级别 16,状态 2,过程 YGTPSAVE,行 11
向 UpdateText 函数传递了 NULL textptr(text、ntext 或 image 指针)。
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
大力这是你的代码,我运行报错
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh varchar(20)
as
DECLARE @ptrval binary(16)
insert tableEmployee (EmpCode,EmpPhoto) select @ygbh,0x where @ygbh not in (select EmpCode from tableEmployee where EmpCode is not null)

SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp

GO

exec ygtpsave 0x001,'E002'



(所影响的行数为 0 行)

服务器: 消息 7133,级别 16,状态 2,过程 YGTPSAVE,行 8
向 UpdateText 函数传递了 NULL textptr(text、ntext 或 image 指针)。
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
--可以这样改进
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if not exists(select 1 from tableEmployee where EmpCode=@ygbh)
insert into tableEmployee(EmpCode,EmpPhoto) values(ygbh,@ygtp)
else
begin
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
end
GO

exec ygtpsave 0x8989,'E002'
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
--我的不行吗?

CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if not exists(select 1 from tableEmployee where EmpCode=@ygbh)
insert into tableEmployee(EmpCode,EmpPhoto) values(ygbh,0x)
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
GO

exec ygtpsave 0x8989,'E002'
pengdali 2003-12-05
  • 打赏
  • 举报
回复
if not exists(select 1 from tableEmployee where EmpCode=@ygbh)
和:
if not exists(select * from tableEmployee where EmpCode=@ygbh)
的结果一样只不过*会返回所有列,1只返回一个1


insert into tableEmployee(EmpCode,EmpPhoto)
values(@ygbh,0x)
-------^^^^^^你的参数
pengdali 2003-12-05
  • 打赏
  • 举报
回复
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh varchar(20)
as
DECLARE @ptrval binary(16)
insert tableEmployee (EmpCode,EmpPhoto) select @编号,0x where @编号 not in (select EmpCode from tableEmployee where EmpCode is not null)

SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp

GO

exec ygtpsave 0x8989,'E002'


---------------------------------
select @编号,0x where .......

如果where条件正确就显示


insert ...... select @编号,0x where .......


如果where条件正确就插入
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
if not exists(select ??1 from tableEmployee where EmpCode=@ygbh)
insert into tableEmployee(EmpCode,EmpPhoto) values(??ygbh,0x)
有问号的地方我不懂
pengdali 2003-12-05
  • 打赏
  • 举报
回复
insert tableEmployee (EmpCode,EmpPhoto) select @编号,0x where @编号 not in (select EmpCode from tableEmployee where EmpCode is not null)
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
select @编号,0x

是什么意思
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
insert tableEmployee (EmpCode,EmpPhoto) select @编号,0x where @编号 not in (select EmpCode from tableEmployee)

这句不懂,大力我用了你的还是不行
pengdali 2003-12-05
  • 打赏
  • 举报
回复
不需要if
pengdali 2003-12-05
  • 打赏
  • 举报
回复
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh varchar(20)
as
DECLARE @ptrval binary(16)
insert tableEmployee (EmpCode,EmpPhoto) select @编号,0x where @编号 not in (select EmpCode from tableEmployee)

SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp

GO

exec ygtpsave 0x8989,'E002'
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
--应该这样改:

CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if not exists(select 1 from tableEmployee where EmpCode=@ygbh)
insert into tableEmployee(EmpCode,EmpPhoto) values(ygbh,0x)
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp
GO

exec ygtpsave 0x8989,'E002'
tonysnss 2003-12-05
  • 打赏
  • 举报
回复
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if exists(select * from tableEmployee where EmpCode=@ygbh)
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp

GO

exec ygtpsave 0x8989,'E002'


表中有那条记录
zjcxc 元老 2003-12-05
  • 打赏
  • 举报
回复
WRITETEXT
允许对现有的 text、ntext 或 image 列进行无日志记录的交互式更新。该语句将彻底重写受其影响的列中的任何现有数据。WRITETEXT 语句不能用在视图中的 text、ntext 和 image 列上。

UPDATETEXT
更新现有 text、ntext 或 image 字段。使用 UPDATETEXT 在适当的位置更改 text、ntext 或 image 列的一部分。使用 WRITETEXT 来更新和替换整个 text、ntext 或 image 字段。

tonysnss 2003-12-05
  • 打赏
  • 举报
回复
刚才都对了,为什么我改为以下后,又报刚才那个错
CREATE PROCEDURE YGTPSAVE
@ygtp image,@ygbh char(20)
as
DECLARE @ptrval binary(16)
if not exists(select * from tableEmployee where EmpCode=@ygbh)
SELECT @ptrval = TEXTPTR(EmpPhoto) FROM tableEmployee where EmpCode=@ygbh
UPDATETEXT tableEmployee.EmpPhoto @ptrval 0 0 @ygtp

GO

exec ygtpsave 0x8989,'E002'
加载更多回复(9)

34,590

社区成员

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

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