对于每行,插入到我在使用“For Each Row”循环中的 INSERT INTO 语句时遇到了问题。我想从“Type”列中查找一个类别,并根据该类别选择“COLUMN_NAME”列中的值,从而为每个类别创建一个列表。我认为我的 INSERT INTO 语句有问题。
// Get the current data table
dt = Current Data Table();
colName = "Type";
// Get the column reference
Types = Column( colName );
// Extract all values from the column
allValues = Types << Get Values;
// Get unique values (removes duplicates)
Cats = Associative Array( allValues ) << Get Keys;
// Sort the unique values (optional)
Cats = Sort List( Cats );
// Display results in the log
Show( Cats );
delCats = {"", "-"};
For( i = 1, i <= N Items( delCats ), i++,
Remove From( Cats, As List( Loc( Cats, delCats[i] ) ) )
);
show(Cats);
For For( i = 1, i <= N Items( Cats ), i++,
Spud = Char(Cats(i));
Spud = {};
For Each Row(
// Access column values directly by name
If(:Type = Char(Cats[i]), Insert Into(Spud, :COLUMN_NAME) ;
);
));
陈述。
自动化和脚本编写回复:对于每一行,插入到(如果我理解正确的话)你不需要使用 For Each Row。只需使用 For Each 循环,并结合 << Get Rows Where 语句和数据表下标,即可将值添加到列表中。
回复:对于每一行,插入到提供的代码无法运行,而且由于缺少适当的空格,难以阅读。我猜测它是人工智能生成的,因为它使用了一些奇怪的JSL技术(例如,即使关联数组的键已经排序,它仍然对其进行排序等等)。
仅根据提供的代码(和问题),我不太确定你的目标是什么。但是,你可能在每次循环中都替换了 Spud 列表,这导致了问题。
回复:对于每一行,插入到连续的分配
Spud = Char(Cats(i));
Spud = {};
它们会用第二个元素覆盖第一个元素。它们也位于外层循环内,这就是为什么@jthi认为列表是被重新创建而不是扩展的原因。
添加一个
show( row(), spud, ...etc... );
在日志中多处获取中间结果的语句也可能有所帮助。或者
write( "\!n x=" || char(x) || " y=" || char(y) );
如果你想格式化它的话。或者
write( Eval Insert("\!n x=^x^ y=^y^) );
这样可能更容易阅读。
JSL 编辑器有一个重新格式化命令,可以帮助解决循环缩进在视觉上错位的问题。