仅使用一次选择查询 [英] use select query only once

查看:97
本文介绍了仅使用一次选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用备注"列维护历史记录.
表示

如果table(tblclass)有一些更改,请在更新cname = ravi
后说cname = manoj 比history(tblclasshistory)备注refelct为:

hi to all,

i am maintaining history with remark column.
means

if table(tblclass) have some change say cname= manoj after update cname=ravi
than in history(tblclasshistory) remark refelct as :

Remarks
ClassName(ravi)(manoj)



我使用了说明表



i use antoher table that is descritption

fieldname         Description
cname              classname
rno                 rollnumber



问题是当我需要使用变更记录的描述时必须两次使用选择查询



problem is that i have to use select query two time when i need to use of description of change record

create procedure test
(
@cname varchar(20),
@rno int

)
as

update tblclass set cname=@cname, rno=@rno 
--to chech if their is any diffence for history
select desription from [description] where fieldname='cname'
select desription from  [description] where fieldname='rno'


problem is that if 20 reocrd change than i dont want use avobe select query twenty time to get description of change reocrd

please help

推荐答案

我们对您的查询有点不清楚.

这是我们的理解:
您有一个名为tblclass的表,另一个名为"Description"的表来跟踪更改的历史记录.假设tblclass中有一行,其cname为"manoj",如果有人更新了该记录并将cname命名为"ravi",那么您需要描述表中的历史记录为"Classname(ravi)(manoj)""

如果上面的理解是正确的,那么下面是我的解决办法

您尚未指定tblclass的确切表架构和描述,因此我正在考虑使用此方法
tblclass(rno bingint,cname nvarchar(50))
说明(rno bigint,备注NVARCHAR(MAX))

1)在tblclass表上的触发器下面编写
We are little bit clear about your queries.

Here is what we understand :
"You have one table called as tblclass and another table called "Description" to track history of changes.Suppose there is one row in tblclass which has cname as "manoj" if some one update that record and made cname as "ravi" then you need history in description table as "Classname(ravi)(manoj)" "

If above understanding is correct then below is my solution

You have not specified exact table schema of tblclass and description so I am considering this
tblclass (rno bingint,cname nvarchar(50))
description (rno bigint , remark NVARCHAR(MAX))

1) Write below trigger on tblclass table
CREATE  TRIGGER [dbo].[tblclass_Update_History]
   ON  [dbo].[tblclass]
   AFTER UPDATE
AS
BEGIN
   INSERT INTO Description(rno,remark)
   SELECT rno,'Classname (' + d.cname + ')(' + I.cname + ')' FROM INSERTED I INNER JOIN Deleted D ON  I.rno=D.rno WHERE I.cname <> D.cname

END



希望这对您有帮助,然后接受并投票答复,否则将返回您的查询.
--RDBurmon高级软件工程师



Hope this helps if yes then accept and vote the answer otherwise revert back with your queries.
--RDBurmon Sr.Software Engineer


这篇关于仅使用一次选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆