是否有可能在不使用遊標的情況下爲選擇的每一行執行一些代碼?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