Home

Creating a stored function with parameters

%3CLINGO-SUB%20id%3D%22lingo-sub-208045%22%20slang%3D%22en-US%22%3ECreating%20a%20stored%20function%20with%20parameters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-208045%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20would%20like%20to%20create%20a%20stored%20function%20that%20has%20input%20parameters.%20Is%20there%20a%20way%20I%20can%20do%20this%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERight%20now%20I%20have%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%2F%2F%20---%20Start%20of%20stored%20function%20------%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3Elet%20DiffUsers%20%3D%20(vmid%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%20%3CSPAN%3Estring%3C%2FSPAN%3E%3CSPAN%3E%2C%20ts1%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%20%3CSPAN%3Edatetime%3C%2FSPAN%3E%3CSPAN%3E%2C%20ts2%3C%2FSPAN%3E%3CSPAN%3E%3A%3C%2FSPAN%3E%20%3CSPAN%3Edatetime%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%7B%3C%2FDIV%3E%0A%3CDIV%3E...%3C%2FDIV%3E%0A%3CDIV%3E%7D%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CP%3E%2F%2F%20---%20End%20of%20stored%20function%20------%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20when%20trying%20to%20call%20DiffUsers(vmid%2C%20ts1%2C%20ts2)%20outside%20of%20the%20stored%20function%20I%20get%20an%20error.%3C%2FP%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-208045%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-356224%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20a%20stored%20function%20with%20parameters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-356224%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F68646%22%20target%3D%22_blank%22%3E%40Evgeny%20Ternovsky%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAny%20idea%20when%20this%20feature%20will%20be%20lightened%20up%3F%3CBR%20%2F%3Ewe%20are%20looking%20forward%20to%20use%20saved%20function%20with%20parameters.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-320470%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20a%20stored%20function%20with%20parameters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-320470%22%20slang%3D%22en-US%22%3EMaking%20this%20possible%20would%20an%20be%20incredibly%20useful%20addition%20to%20Log%20Analytics%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-210153%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20a%20stored%20function%20with%20parameters%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-210153%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20use%20a%20let%20statement%20as%20in%20your%20example%20to%20serve%20the%20same%20purpose%20as%20a%20SProc.%20Today%2C%20however%2C%20this%20is%20only%20possible%20at%20query%20time%3B%20you%20cannot%20unfortunately%20save%20these%20as%20a%20%22function%22%20the%20same%20way%20that%20you%20can%20with%20views.%20It%20is%20something%20on%20our%20backlog%2C%20but%20will%20take%20a%20while%20to%20properly%20implement.%20For%20more%20details%20on%20the%20query-time%20options%20available%2C%20check%20out%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.loganalytics.io%2Fdocs%2FLanguage-Reference%2FMisc%2FUser-defined-functions%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Earticle%20on%20UDFs%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Benjamin Girardeau
Microsoft

Hi,

 

I would like to create a stored function that has input parameters. Is there a way I can do this?

 

Right now I have:

 

// --- Start of stored function ------

let DiffUsers = (vmid: string, ts1: datetime, ts2: datetime)
 {
...
};

// --- End of stored function ------

 

But when trying to call DiffUsers(vmid, ts1, ts2) outside of the stored function I get an error.

 
3 Replies

You can use a let statement as in your example to serve the same purpose as a SProc. Today, however, this is only possible at query time; you cannot unfortunately save these as a "function" the same way that you can with views. It is something on our backlog, but will take a while to properly implement. For more details on the query-time options available, check out the article on UDFs.

Making this possible would an be incredibly useful addition to Log Analytics

Hi @Evgeny Ternovsky,

 

Any idea when this feature will be lightened up?
we are looking forward to use saved function with parameters.

 

Thanks.

Related Conversations
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
2 Replies
*Updated 9/3* Syncing in Microsoft Edge Preview Channels
Elliot Kirk in Articles on
205 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies