在SQL Server 2008中循环 [英] Looping in SQL Server 2008
问题描述
亲爱的编码员,
我有以下查询..
触发查询时,我得到以下数据:
UNITECH
旁遮普语
JPASSOCIAT
HDIL
DENABANK
KOKUYOCMLN
ASHOKLEY
IOB
现在我想做的是,当我得到这些数据时,我想一一对应地根据我上面得到的值来一一更新记录.
例如,获取上述记录后,我想根据公式更新一些列.所有这些记录的公式都相同.
基本上这是股票名称,我想根据情况更新股票移动AVG.
可以在一个查询中完成吗?
致谢.
Dear Coders,
I have following query..
I get following data when i fire a query:
UNITECH
PUNJLLOYD
JPASSOCIAT
HDIL
DENABANK
KOKUYOCMLN
ASHOKLEY
IOB
Now what i want to do is when i get this data then one by one i want to update the records one by one based on the values which i got above.
For e.g.After getting the above records i want to update some columns based on formula.The formula will be same for all these records.
Basically this are stock names & i want to update the stock moving AVG based on the condition.
Can this done in one query?
Thanks & Regards.
推荐答案
SQL Server 2008中有一项新功能Merge,它是Cursor的替代品.
您可以参考以下文章来解决您的问题:
SQL Server 2008中的合并语句 [ http ://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/ [ ^ ]
谢谢,
Jitendra
There is new feature Merge in SQL Server 2008 which is replacement of Cursor.
You can refer below articles to solve your problem:
Merge Statement in SQL Server 2008[^]
http://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/[^]
Thanks,
Jitendra
这篇关于在SQL Server 2008中循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!