我想在存储过程中执行一个查询,它应循环所有数组值.
例如:
declare arrayStoreID={1001,2400,2001,5000} for(int i=0;i我想像上面那样表现.谢谢
1> Susang..:First Store ID
temporary table
如下所示create table #Table_Name(storeID INT, col_name1 varchar(50), col_name2 varchar(50)) insert into #Table_Name values (1001, 'Test1', 'Test2'), (5000, 'Rest1', 'Rest2'), (1122, 'Best1', 'Best2')然后你可以加入你想要获取记录的表格,如下所示,这种方法比通过
loop
你的要求不是more complicated
真实的要好得多.select t.col_name1, t.col_name2 INTO #new_table from #Table_Name t inner join #tmp_ids ti on ti.id = t.storeID它将返回与上面匹配
IDs
并插入的 两条记录#new_table
select * from #new_table OUTPUT: col_name1 col_name2 Test1 Test2 Rest1 Rest2 Note: you can use `table variable` as well