Referencing a VB variable or constant
Using inline VB in a query, how can I declare a variable or constant at the top and reference it later?
<% Dim sMsg As String = "hello"%>
SELECT * FROM MYTABLE WHERE SOMECOLUMN='<% Return sMsg %>'
This feature is implemented in Log Parser Lizard 4.0.3. You can find more info in comments.
-
Nick Reid commented
Fantastic! Great!
Thank you very much.
Nick
-
Log Parser Lizard v4.0.3 now supports similar functionality. Now you can write query like:
<% Dim id As String = "1"%>
SELECT * FROM System WHERE EventType='<% Output.Append(id) %>'
LPL will automatically transform and run this in one Visual Basic .NET script:
Dim Output As New System.Text.StringBuilder
Output.Append("")
Dim id As String = "1"
Output.Append("")
Output.Append("")
Output.Append("SELECT * FROM System WHERE EventType='")
Output.Append(id)
Output.Append("'")
Return Output.ToString()I believe something like this is what you were looking for.
Please note that to enable this VB.Net script behavior you will have to modify the setting “Execute inline VB.Net scripts separately” in Settings dialog box. We had to default this setting to True to keep compatibility with scripts from previous LPL versions.
If you want to use this behavior from now on, maybe you will have to modify some current queries. If you have more than one script block in a query, just remove the “RETURN” statement from each block since it will break the script execution.
I hope this was helpful and all of you have voted will enjoy the new feature.
Lizard Labs
-
Steve C commented
It's a hack, but how about...
<%Environment.SetEnvironmentVariable("sMsg","hello")%>
SELECT * FROM MYTABLE WHERE SOMECOLUMN='<%RETURN Environment.GetEnvironmentVariable("sMsg")%>'