Hi everyone,
Is it possible to use a "variable" field you have just created in a query, as a term for other columns in that query? Using Access 2013 query design.
I am pulling out dates as text that might be written like "8-1-2010 1:00" or might be "12-30-2010 17:35". The position of the dashes and spaces is important to parsing. If I can put the position in a variable(s), it makes other equations easier. For example
have a field say:
DashPos1: InStr( [Timestamp], "-"])
DashPos2: InStr( DashPos1+1, [Timestamp], "-")
Then it makes equations easier. Say I want to turn those timestamps into e.g. a date field as YYYY-M-D:
= mid(DashPos2+1, [Timestamp], 4) & "/" & mid( [TimeStamp, DashPos1-1) & "/" & mid(DashPos1+1, [Timestamp], DashPos2-DashPos1 )
This equation is probably not 100% correct but don't worry about making it correct; you see what I'm trying to do, and how the "variables" make the date equation a lot shorter and a lot easier mentally (to not have commas and parens in the wrong place of
a god-awful long equation, etc.)
If I try the equation above, it simply considers the variable terms as text strings themselves (it puts quote marks around them). Of course, that's not going to work at all.
I know that in SAS you can make a variable anywhere by putting && in front of some term, and then this gets "turned into" whatever the variable stood for when you run the SAS code. Wow, you could do some really funky things with that (variables that parsed
into other variables or other code, etc.). But then SAS is closer to real code than the Access query window.
I've seen and used SQL and the SQL query view before, and can probably handle a SQL answer.
Please note, I am a data hobbyist and am always dealing with new datasets of different types. I am not making an app and nothing is fixed. So please, no VBA or other complicated superstructures. I am just and only asking, straight up, is there some sort
of way to have a variable within a query, that was created right in that query.
Otherwise I guess the worse case is I have to build a second query on top of the first one (or make new fields) with those new variables. And yes I can do that. But that's not the answer I'm looking for. The question is, do I have to? Or can I avoid making
extra queries and fields, and just directly make a value and use it within my one query somehow, already.
Thanks if you can help!