SOLVED
Home

How to pass dynamic data to the "Where Condtion"

%3CLINGO-SUB%20id%3D%22lingo-sub-259849%22%20slang%3D%22en-US%22%3EHow%20to%20pass%20dynamic%20data%20to%20the%20%22Where%20Condtion%22%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-259849%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3ECan%20some%20one%20help%20me%20how%20to%20pass%20the%20variable%20data%20dynamically%20in%20where%20condition%20for%20log%20analytics%20query%20.%20below%20query%20is%20not%20executing%20%2C%20it%20is%20telling%20that%20%22Syntax%20Error%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExample%20%3A%3C%2FP%3E%3CP%3Elet%20%3CSTRONG%3EID%3C%2FSTRONG%3E%3D%20customatable%20%7C%20top%201%20by%20TimeGenerated%20%7C%20summarize%20by%20id%3C%2FP%3E%3CP%3Esearch%20Column%20%3D%20%22ABC%22%20%7C%20where%20id%20%3D%3D%20%3CSTRONG%3EID%3C%2FSTRONG%3E%7C%20sort%20by%20timmegenerated%20desc%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-259849%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-267453%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20pass%20dynamic%20data%20to%20the%20%22Where%20Condtion%22%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-267453%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Patrick%20%2C%3C%2FP%3E%3CP%3ESorry%20for%20the%20late%20reply..%20I%20got%20other%20solution...%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20yes%20It%20is%20working%20as%20well%2C%20appreciate%20your%20help..%20thank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-263143%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20pass%20dynamic%20data%20to%20the%20%22Where%20Condtion%22%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-263143%22%20slang%3D%22en-US%22%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3Elet%20ID%20%3D%20toscalar%3C%2FSPAN%3E%3CSPAN%3E(customtable_CL%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%7C%20%3C%2FSPAN%3E%3CSPAN%3Etop%3C%2FSPAN%3E%20%3CSPAN%3E1%3C%2FSPAN%3E%20%3CSPAN%3Eby%3C%2FSPAN%3E%3CSPAN%3E%20TimeGenerated%20desc%20%7C%20%3C%2FSPAN%3E%3CSPAN%3Eproject%3C%2FSPAN%3E%3CSPAN%3E%20id%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Ecustomtable_CL%20%7C%20%3C%2FSPAN%3E%3CSPAN%3Ewhere%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E%20Columname%20%3D%3D%20%3C%2FSPAN%3E%3CSPAN%3E%22ABC%22%3C%2FSPAN%3E%20%3CSPAN%3Eand%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Bid%20%3D%3D%20ID%20%7C%20%3C%2FSPAN%3E%3CSPAN%3Eorder%3C%2FSPAN%3E%20%3CSPAN%3Eby%3C%2FSPAN%3E%3CSPAN%3E%20TimeGenerated%20desc%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-260320%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20pass%20dynamic%20data%20to%20the%20%22Where%20Condtion%22%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-260320%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%20for%20response..%3C%2FP%3E%3CP%3ESorry%20for%20typo(mistakenly%20keyed)%2C%20But%20I%20have%20tried%20exactly%20below(semicolon%20after%20let%20statement%20and%20correct%20spelling%20for%20TimeGenerated)%20%2C%3C%2FP%3E%3CP%3Eerro%20is%20%22%3CSPAN%3E'where'%20operator%3A%20Failed%20to%20resolve%20column%20or%20scalar%20expression%20named%20'id'%26nbsp%3B%3C%2FSPAN%3E%22%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Elet%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3D%20customatable%20%7C%20top%201%20by%20TimeGenerated%20%7C%20summarize%20by%20id%3B%3C%2FP%3E%3CP%3Esearch%20Columname%20%3D%20%22ABC%22%20%7C%20where%20id%20%3D%3D%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%7C%20sort%20by%20%3CSPAN%3ETimeGenerated%26nbsp%3B%3C%2FSPAN%3Edesc%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-259946%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20pass%20dynamic%20data%20to%20the%20%22Where%20Condtion%22%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-259946%22%20slang%3D%22en-US%22%3E%3CP%3EI%20see%20a%20couple%20things%20that%20could%20cause%20the%20error.%26nbsp%3B%20There%20is%20no%20semicolon%20at%20the%20end%20of%20the%20let%20statement%20and%20TimeGenerated%20on%20the%20second%20line%20is%20incorrect.%26nbsp%3B%20It%20looks%20like%20you%20are%20referencing%20custom%20logs%20so%20I%20can't%20run%20it%20in%20the%20demo%20site%20to%20better%20test.%26nbsp%3B%20If%20you%20are%20not%20already%2C%20try%20running%20the%20query%20in%20the%20new%20%22Logs%22%20Blade%20in%20the%20Log%20Analytics%20portal.%26nbsp%3B%20Analytics%20has%20auto-complete%20and%20error%20indication%20that%20may%20help%20weed%20out%20syntax%20errors.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
subrahmanyam kommireddy
New Contributor

Hi,

Can some one help me how to pass the variable data dynamically in where condition for log analytics query . below query is not executing , it is telling that "Syntax Error"

 

Example :

let ID = customatable | top 1 by TimeGenerated | summarize by id

search Column = "ABC" | where id == ID | sort by timmegenerated desc

4 Replies

I see a couple things that could cause the error.  There is no semicolon at the end of the let statement and TimeGenerated on the second line is incorrect.  It looks like you are referencing custom logs so I can't run it in the demo site to better test.  If you are not already, try running the query in the new "Logs" Blade in the Log Analytics portal.  Analytics has auto-complete and error indication that may help weed out syntax errors.

 

Thank you for response..

Sorry for typo(mistakenly keyed), But I have tried exactly below(semicolon after let statement and correct spelling for TimeGenerated) ,

erro is "'where' operator: Failed to resolve column or scalar expression named 'id' 

 

let ID = customatable | top 1 by TimeGenerated | summarize by id;

search Columname = "ABC" | where id == ID | sort by TimeGenerated desc

let ID = toscalar(customtable_CL | top 1 by TimeGenerated desc | project id);
customtable_CL | where  Columname == "ABC" and id == ID | order by TimeGenerated desc
Solution

Hi Patrick ,

Sorry for the late reply.. I got other solution... 

And yes It is working as well, appreciate your help.. thank you.