Skip to content

Instantly share code, notes, and snippets.

@cbaragao
Created January 2, 2025 23:03
Show Gist options
  • Save cbaragao/e60756643cffcb74810d786ad6cb1d9b to your computer and use it in GitHub Desktop.
Save cbaragao/e60756643cffcb74810d786ad6cb1d9b to your computer and use it in GitHub Desktop.
let
fnGetSQLServer =
let
GetSQLServerType = type function (
server as (
type text
meta [
Documentation.FieldCaption = "Server Name",
Documentation.FieldDescription = "SQL Server name",
Document.SampleValues = {"SERVER"},
Formatting.IsMultiLine = false,
Formatting.IsCode = true
]
),
database as (
type text
meta [
Documentation.FieldCaption = "Database Name",
Documentation.FieldDescription = "Database name",
Document.SampleValues = {"Database"},
Formatting.IsMultiLine = false,
Formatting.IsCode = true
]
),
sql as (
type text
meta [
Documentation.FieldCaption = "SQL",
Documentation.FieldDescription = "SQL Query Text",
Document.SampleValues = {"SELECT * FROM your_table"},
Formatting.IsMultiLine = true,
Formatting.IsCode = true
]
)
) as table,
GetData = (server as text, database as text, sql as text) as table =>
Value.NativeQuery(
Sql.Databases(server){[Name=database]}[Data],
sql,
null,
[EnableFolding = true, PreserveTypes = true]
)
in
Value.ReplaceType(GetData, GetSQLServerType)
in
fnGetSQLServer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment