Wednesday, March 22, 2023

ISNULL in Databricks SQL

Use 

 coalesce

coalesce(member_count,0)

Wednesday, March 8, 2023

Command line executable sql server ChatGPT

 A command line executable for SQL Server is a file that can run SQL queries or scripts using a command-line utility such as sqlcmd123. It usually has an extension like .sql or .bat. To run a command line executable for SQL Server, you need to know its file path and use the appropriate syntax for your utility. For example:


In sqlcmd, you can use the -i option to specify the input file name. For example: sqlcmd -S server_name -d database_name -i C:\Scripts\script.sql

In a batch file, you can use the sqlcmd command with the input file name as an argument. For example: sqlcmd -S server_name -d database_name -i C:\Scripts\script.sql

You can also pass other options to the sqlcmd utility, such as -o to specify the output file name, -v to define variables, or -q to execute a query directly. For more information on sqlcmd options, see here.


If you want to create your own command line executable for SQL Server, you can

Tuesday, March 7, 2023

ChatGPT Open AI Excel VBA error

This code is generated by ChatGPT but still getting error to connect to API. help.

Error in this line: request.send JsonConverter.ConvertToJson(body)


 Sub ChatItem()

    'Declare variables

    Dim request As Object

    Dim response As String

    Dim url As String

    Dim headers As Object

    Dim body As Object

    

    'Set url and headers for API call

    url = "https://api.openai.com/v1/engines/chatgpt/completions"

    Set headers = CreateObject("Scripting.Dictionary")

    headers.Add "Authorization", "sk-xxxxxxxxxxxxxxxx" 'Replace with your API key

    

    'Set body for API call with prompt and parameters

    Set body = CreateObject("Scripting.Dictionary")

    

    'Get item name from cell A1

    Dim item As String

    item = Range("A1").Value

    

    'Set prompt to chat about the item using ChatGPT's persona

    body.Add "prompt", "The following is a conversation with ChatGPT, an AI assistant that can help you with Excel tasks. ChatGPT knows how to use VBA and can generate code snippets for you.\n\nHuman: Hi, I want to chat about " & item & ".\nChatGPT:"

    

    'Set parameters for completion such as temperature, max_tokens, etc.

    body.Add "temperature", 0.5 'Lower temperature means more predictable responses

    body.Add "max_tokens", 50 'Maximum number of tokens to generate

    body.Add "stop", "\nHuman:" 'Stop generating when encountering this sequence

    

     'Create a new request object

     Set request = CreateObject("MSXML2.XMLHTTP")

     

     'Send a POST request with the url, headers and body as JSON string

     request.Open "POST", url, False

     For Each Key In headers.keys

        request.setRequestHeader Key, headers(Key)

     Next Key

     

     request.send JsonConverter.ConvertToJson(body)

     

     'Get the response text as JSON object and extract the generated text

     response = request.responseText

     Set json = JsonConverter.ParseJson(response)

     

     Dim generated_text As String

     generated_text = json("choices")(1)("text")

     

     

    

End Sub