The code below is an attempt to summarize my understanding of the difference between Column() and As Column().
//PMroz example table
dt=New Table( "Search Example",
Add Rows( 6 ),
New Column( "Sample Means",
Character,
Set Values(
{"1. blood sample", "2. blood sample", "1. serum sample",
"2. serum sample", "1. cardio sample", "2. cardio sample"}
)
)
);
// Column("X") returns a column reference.
// As Column("X") is equivalent to :X, giving access to the values of Column("X").
// Without an index, :X returns the value of the current row.
//
Row() = 3;
x = As Column( dt, "Sample Means" );
y = dt:Sample Means;
col = Column( dt, "Sample Means" );
Show( x, y, col );
// However, with an index (e.g. :X and Column("X")) both the current row
//and the column reference is bypassed; and both commands yield the same result.
x = dt:Sample Means[1];
y = Column( dt, "Sample Means" )[1];
Show( x, y );
// Hence, the below messages using As Column() Or Column()[] are equivalent.
// The empty square brackets ensures that "Select Where" loops through the value of each row.
//Without them, it would repeatedly look for a string in a column reference which would fail every time.
dt << select where(
Contains( Column( dt, "Sample Means" )[], "blood" ) |
Contains( Column( dt, "Sample Means" )[], "serum" )
);
dt << select where(
Contains( As Column( dt, "Sample Means" ), "blood" ) |
Contains( As Column( dt, "Sample Means" ), "serum" )
);