Tag: AIExperiments

  • Quick Wins with GenAI

    The more I look to GenAI to save me minutes, short periods of time, the better it works. Here’s an example of something I do regularly where AI helps.

    This is part of a series of experiments with AI systems.

    Reformatting code

    I often see code like this submitted in articles.

    2025-06_line0083

    The code conversion box often adds extra lines between code. It’s a strange error, and since things get pasted in with lots of formatting, it’s not so simple to fix. I often look at the code side of things and remove lines. This is the raw code:

    2025-06_line0081

    It’s ugly, and it’s easy to fix, but it takes time and it can be an annoying task. I often might put on a video or multi-task while I handle this simple reformat.

    Using Claude

    Claude is often my go-to GenAI for now. I tried this prompt, with a CTRL+V of the code. As you can see, Claude starts to reason things out.

    2025-06_line0084

    On the right side, I can see it rewriting code, which is always fascinating. Reminds me of terminal work over a 300baud modem in university. I’ve grabbed a short snippet of how this works.

    Once this is done, I see my code on the right code. I can click “Copy” at the top and then paste back into the editor. It looks much better.

    2025-06_line0082

    This allows me to move on and tackle some other task before I come back to this, knowing Claude will have helped me.

    Small wins, very helpful, but a lever to make me more productive.

    I don’t know if this is worth the cost in computing, but it is very helpful. Minutes saved are likely worth a small subscription to the tool every month if I can find a few more tasks like this.

  • Using a GenAI to Help Brent

    Brent had a query exercise recently about train stations moving in some order and having overrides to this order in emergencies. I suppose he’s been traveling a lot lately and ran into an issue.

    In any case, I decided to see if Claude could solve his challenge.

    This is part of a series of experiments with AI systems.

    The Prompt

    I put this into Claude, mostly copy/paste from Brent’s challenge.

    I have a sql table of stations in a physical order. Here is the table and data for stations DROP TABLE IF EXISTS dbo.Stations; CREATE TABLE dbo.Stations     (StationId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,      StationName VARCHAR(50),      StationPhysicalOrder INT); INSERT INTO dbo.Stations (StationName, StationPhysicalOrder)     SELECT CHAR(64 + n), n     FROM (VALUES         (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),         (12),(13),(14),(15),(16),(17),(18),(19)     ) AS Numbers(n);

    I also have an override table, which contains its own data for emergencies. Here is this code: Transact-SQL 1 2 3 4 5 6 7 8 DROP TABLE IF EXISTS dbo.StationRoutingOverride; CREATE TABLE dbo.StationRoutingOverride     (StationRoutingOverrideId INT IDENTITY(1,1) PRIMARY KEY CLUSTERED,      StationFromName VARCHAR(50),      StationToName VARCHAR(50)); INSERT INTO dbo.StationRoutingOverride (StationFromName, StationToName)     VALUES (‘E’, ‘S’), (‘B’, ‘I’), (‘I’, ‘D’);

    write a query to return a result set that: * Starts with the station with the lowest StationPhysicalOrder * For each row, if there’s a row in StationRoutingOverride to dictate the next step, jump to that station * Otherwise, go to the station with the next StationPhysicalOrder

    The Answer

    Here’s the code:

    WITH StationRouting AS (
         -- Base case: Start with the station having the lowest StationPhysicalOrder
         SELECT 
             s.StationId,
             s.StationName,
             s.StationPhysicalOrder,
             1 as StepNumber
         FROM dbo.Stations s
         WHERE s.StationPhysicalOrder = (SELECT MIN(StationPhysicalOrder) FROM dbo.Stations)
         
         UNION ALL
         
         -- Recursive case: Find the next station
         SELECT 
             next_station.StationId,
             next_station.StationName,
             next_station.StationPhysicalOrder,
             sr.StepNumber + 1
         FROM StationRouting sr
         CROSS APPLY (
             SELECT TOP 1
                 s.StationId,
                 s.StationName,
                 s.StationPhysicalOrder
             FROM dbo.Stations s
             WHERE s.StationName = COALESCE(
                 -- First priority: Check if there's an override for current station
                 (SELECT sro.StationToName 
                  FROM dbo.StationRoutingOverride sro 
                  WHERE sro.StationFromName = sr.StationName),
                 -- Second priority: Next station by physical order
                 (SELECT TOP 1 s2.StationName 
                  FROM dbo.Stations s2 
                  WHERE s2.StationPhysicalOrder > sr.StationPhysicalOrder 
                  ORDER BY s2.StationPhysicalOrder)
             )
         ) next_station
         WHERE next_station.StationName IS NOT NULL
    )
    SELECT 
         StepNumber,
         StationId,
         StationName,
         StationPhysicalOrder
    FROM StationRouting
    ORDER BY StepNumber;

    That doesn’t work, so I added to the prompt:

    2025-06_line0046

    I got a similar error again with the group by in the CTE and pasted that in. The query got rewritten (Again) and this time it ran with this result, which matches Brent’s answer.

    2025-06_line0047

    GenAIs make mistakes, but they can also fix things. I wondered how well this would work, but it worked well. I merely told the model it had made an error and it tried again.

    Imagine if the AI could connect to a db, run its code, and adjust from the error messages itself? The higher end coding tools are supposed to do this.

  • Generating Random Strings with GenAI

    One of the things I’ve been experimenting with in AI is taking things other people do and seeing how well the AI works. In this case, I took a Prompt from Louis and tried to see how well it worked. This post describes the results from a few models.

    This is part of a series of experiments with AI systems.

    The Challenge Using Claude

    Louis was using an AI to generate some test data to play with the new Regex functionality in SQL Server 2025. He put this in ChatGPT: “create a set of random string data with 1000 rows for a sql server table named RegExTest. It should insert data into a column named Value”.

    He had mixed results with ChatGPT, which I tend not to use. Instead, I tried this in Claude. I like Claude as I get an explanation separate from the code. Here’s a view of the page:

    2025-06_line0031

    Here’s the code, which is nice because I could steal certain patterns out of here if I had the need. The explanation was also good, and I’ve reproduced that here:

    <start claude explanation>

    This SQL script creates 1000 rows of diverse random string data for your RegExTest table. The data includes various patterns that are useful for testing regular expressions:

    • Email addresses (user@domain.com)
    • Phone numbers ((123) 456-7890)
    • Dates (MM/DD/YYYY)
    • Mixed alphanumeric with special characters (ABC-123_XYZ)
    • Numeric strings (123456)
    • URL patterns (https://www.example.com/path)
    • Code patterns (AB12C345)
    • Words with spaces (Hello World)
    • Mixed case strings (AbCdEf123)
    • Random alphanumeric strings

    The script uses a recursive CTE to generate 1000 rows and applies different string generation patterns based on the row number modulo operations. This ensures you get a good variety of data types to test your regular expressions against.

    The script also includes table creation (if it doesn’t exist) and verification queries to confirm the data was inserted successfully.

    <end claude explanation>

    There was an issue in the else part of the CASE. The last CONCAT call only had the first parameter and CONCAT needs two parameters, so I copy/pasted the 2nd parameter from the last THEN statement, which worked fine. In this case, that parameter was an acceptable choice to create a random alpha string.

    Perplexity

    I got a very weak result from Perplexity. Essentially, write insert statements, though you could use a script.

    2025-06_line0037

    I didn’t see a script, so I asked. I got this.

    2025-06_line0039

    Here’s the SQL Code:

    2025-06_line0040

    That’s weak. It works, but it’s weak and I think I could have written that in not much more time than the AI took.

    It did end with this sentence: Let me know if you want the script in another format or with different string lengths!

    I did and then got a series of different scripts for different formats, but each was producing a separate 1000 rows of only that format.

    DeepSeek

    I download the DeepSeek coder model and decided to try that. The basic prompt was disappointing. The model basically wanted to use Python and only imported modules without other code.

    2025-06_line0041

    When I said that and asked for code, I got more details, but with the script separated out into sections. The top seemed to repeat a bit.

    2025-06_line0042

    Then I got each part of the script.

    2025-06_line0043

    I didn’t run this, but it’s a reasonable way to do things for developers. For data people, this seems like overhead.

    I asked for SQL, and got a script for Oracle, but more interesting, the code is for 1000 rows, but the comments say ten thousand. Can’t the GenAI count?

    2025-06_line0044

    I asked to change this to SQL Server and got this code.

    2025-06_line0045

    I don’t know what to say except that I’m disappointed in the local deepseek model, which is not only slow, but hasn’t produced a good answer.

    Summary

    Claude clearly wins this experiment.

  • Getting References for GenAI Results

    I wrote an editorial on the view of GenAI tech from execs and someone commented that they wanted references for results. Most of us might take a result from a co-worker and use it without asking for any proof of where it comes from. If we trust our co-workers, this can work well. If we don’t, then we might want to know where they learned this and how they know it works.

    For GenAI, we might want some references to help us learn more or check something. Or, more likely, learn how to modify something that isn’t perfect.

    In this sense, GenAI can be better as this gives us the references we need to learn how the answer was generated.

    This post looks at how I got references in a few cases using Claude, Perplexity, and Copilot.

    This is part of a series of experiments with AI systems.

    Asking a Question

    I decided to ask a question that I was asked by someone and I used Copilot to find the answer. Here is my prompt:

    I need to schedule a Powershell script to access a SQL Server and want to use a managed service account to run the script. How can I do this in powershell

    Let’s look at how the various tools I’ve used respond.

    Claude

    Claude.ai is from Anthropic and it’s a tool I’ve enjoyed using. When I pasted in the prompt, I saw this response:

    2025-05_0222

    I got to the bottom and no references, but when I asked for them (see my prompt in the image), I got a few to look at.

    2025-05_0223

    That’s one of the tricks with AI. You can ask it to explain itself.

    Perplexity

    My second test was perplexity, which I started to use a bit after Grant mentioned it.

    2025-05_0220

    Right at the top, I get some references that I can click. When I get to the bottom, I have a list of possible future prompts, which aren’t references, but they get me thinking about things I might need to consider.

    2025-05_0221

    That worked well and I liked having the references, though I’d prefer them at the end.

    Copilot

    I decided to try Copilot inside of VS Code, which is where I’d likely use it. I entered the prompt as a comment in a blank .ps1 file. After my first line, it suggested a few more comments to give context. I accepted a few and then added the last #include references line.

    2025-05_0224

    I didn’t get references and the generation stopped at the #End of script line.

    I then added the comment below asking for URL references.

    2025-05_0225

    Each of the items above appeared as a line in italics, like other suggestions. I hit Tab to accept and I’d get another reference. When I saw the last one repeat, I stopped the responses.

    Summary

    I’m not evaluating the code here, just trying to see if I could get some idea of where the code came from. In this case, I don’t deal with MSAs a lot, so it’s good that I can get some URLs to check docs or get more options other than the code I found.

    If I asked this question on Stack Overflow, I might get the same code (or similar), but getting URLs or references isn’t always easy there. Some people provide them, some don’t, and some might just close my question and say I should have searched better.

    I think the GenAI does a good job here of giving me a starting point, and a place to go, which is helpful.