Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello Qlikview experts,
I am trying to write below script to a text file, I have stored it to a variable called sampletable. How do I write it to a text file? I am using STORE to do this, is this a correct way because i am getting error "Syntax error, missing/misplaced FROM:store". Please help with the syntax. Thank You all in advance.
let sampletable = 'SQL SELECT sum($(qry_count_s1)),sum($(qry_count_s2)),sum($(qry_dur_s1)),sum($(qry_dur_s2)),
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH,
FROM $(qry_table_name)
group by
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH,
';
store $(sampletable) into C:\Qlikview\buildsql.txt
Hi padmasali!
The Store command in load scripts is used to store tables only.
You could write the content of a variable to a file, using VB (that is, using Macro Script).
An alternative is to get the variable in to a table (SampleTable in example below), like this:
SampleTable:
Load * Inline [
SampleText
"SQL SELECT sum($(qry_count_s1)),sum($(qry_count_s2)),sum($(qry_dur_s1)),sum($(qry_dur_s2)),
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH,
FROM $(qry_table_name)
group by
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH"
];
Store SampleTable Into C:\Qlikview\buildsql.txt (txt);
(There may be syntax errors above, but it shows the general idea anyway)
hth/gg
edit: PS
Giles solution seems more elegant...
hi,
you have to add a load statement between the "let" and "store" statement, like this :
tab1:
load $(sampletable) autogenerate 1;
store tab1 into C:\Qlikview\buildsql.txt (txt);
hope this helps
Gilles
Hi padmasali!
The Store command in load scripts is used to store tables only.
You could write the content of a variable to a file, using VB (that is, using Macro Script).
An alternative is to get the variable in to a table (SampleTable in example below), like this:
SampleTable:
Load * Inline [
SampleText
"SQL SELECT sum($(qry_count_s1)),sum($(qry_count_s2)),sum($(qry_dur_s1)),sum($(qry_dur_s2)),
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH,
FROM $(qry_table_name)
group by
$(qry_s1)_$(qry_s2)_YEAR,
$(qry_s1)_$(qry_s2)_MONTH"
];
Store SampleTable Into C:\Qlikview\buildsql.txt (txt);
(There may be syntax errors above, but it shows the general idea anyway)
hth/gg
edit: PS
Giles solution seems more elegant...
Control+ E -> File meenu->Export to script File
then open into notepad
and save it
Thanks GandalfGray,
Your response helped me in resolving.
Regards
Hello GandalfGray,
Below macro in (first.qvw) will read a text file and writes it to another (recon.qvw) file. The text file contains SQL select statements. I am facing a issue with below code.
1. When I run the macro it just opens the recon.qvw file, but the script is not getting added. Please help.
Thanks & Regards
Padmasali
sub UpdateScriptFromfile
set FSO= createobject("Scripting.FilesystemObject")
set openReconFile=FSO.OpenTextFile("C:\Qlikview\buildsql.txt")
scriptBackup=openReconFile.ReadAll
openReconFile.Close
msgbox(scriptBackup)
set newdoc = GetObject("C:\Qlikview\recon.qvw")
newdoc.GetProperties.Script = scriptBackup
end sub
Hi Padmasali
I have not tried this myself, but I think you need to change the last line before end sub to:
newdoc.SetProperties.Script = scriptBackup
hth/gg