up我是要在SP 里面检测返回的数据 内容 . select TOP 1 @int_userid=id,[name],[url] from [dbo].[user] where name=@str_name and cat_id=@int_catid if @int_userid>0 begin .............. end 像这样的 无法执行 :(
create proc test (@a varchar) as select * from 表 while @@rowcount >0 begin 操作 end; --------------- 或者用游标 ----------- create proc test1(@a varchar(20)) as begin declare csr CurSor for select * from 表 open csr fetch next from csr into 变量 while @@rowcount>0 begin 判断 fetch next from csr into 变量 end; close csr deallocate csr end;
能不能在 查询 数据之后 对查询到的数据进行处理 ?
不是这种 count 的.
select @@rowcount来显示
select * from xpxx Where id=@id --查询数据 if @@RowCount = 0 -- @@RowCount:返回受上一语句影响的行数。
begin
--没有找到数据时插入新数据
Insert a_xpxx
(bc_id, qh, lbmc, no1, no2, no3, no4, no5)
Values
(NEWID(),@qh, @lbmc, @no1, @no2, @no3, @no4, @no5)
Return 1 --插入成功
end
else
--找到新数据时的操作
Return 0
这样不能读取记录呀... 我需要得到 查询返回记录中的 ID,NAME,URL 等几个字段的内容. 大侠看有办法么?
if @int_userid>0
begin
..............
end
像这样的 无法执行 :(
(@a varchar)
as
select * from 表
while @@rowcount >0
begin
操作
end;
---------------
或者用游标
-----------
create proc test1(@a varchar(20))
as
begin
declare csr CurSor for
select * from 表
open csr
fetch next from csr into 变量
while @@rowcount>0
begin
判断
fetch next from csr into 变量
end;
close csr
deallocate csr
end;
begin
…………
end