是否有可能在不使用游标的情况下为选择的每一行执行一些代码?TSQL - 为选择的每一行执行代码
在我的情况: 我有一个临时表来存储complexe脚本的一些数据。最后,我想将这张表的某些信息(受某些条件限制)输出到输出中。
目前我正在使用带select的游标来限制表的行。在这个游标中,我正在使用
print '...'
生成输出。
必须有做这种事情更简单的方法...
编辑:
create table #tmpAttributes(AttributeId uniqueidentifier, Value float, ValueString nvarchar(max), ActionId uniqueidentifier)
insert into #tmpAttributes (AttributeId, Value, ValueString, ActionId)
select ID,..... -- in this select i'm doing some value conversions, if conversion is not possible i'm using -1
insert into ActionAttribute (ActionDefinitionID, Discriminator, ID, ReferredActionID, ValueDate, ValueListID, ValueMoney, ValueString, ValueUserID)
select @defId, 'ActionAttributeMoneyEntity', NEWID(), ActionId, null, null, Value, null, null from #tmpAttributes
-- afterwards there is this cursor where I'm printint all rows where Value = -1
没有足够的信息。你究竟在努力实现什么?如果你给我们一个完整的场景,你可能会发现有一个完全基于集合的方式来执行你所需要的。 – gvee
为什么不在刚刚创建的“临时表”上放置一个额外的标识列,并为每一行循环播放。 –
如果你只是想打印这些信息“最后”,为什么你需要一个光标呢? – DrCopyPaste