Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

SQL Express/SQL Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SQL Express/SQL Server

    Hi everyone,
    I find myself force to update and maintain some files using MSSQL instead of my much preferred MySQL.
    I created the code below (that gets the job done), but I'm wondering if there's a better way to write the sql.

    Any help will be a blessing.

    Gregg
    Code:
    select userid,lname from [user]
    where  left(lname,1) between '0' and '9' and convert(varchar(5),convert(int,userid)) = lname
    Gregg
    https://paiza.io is a great site to test and share sql code

    #2
    Hi Gregg,

    I have only used MSSQL and have found most of the syntax to be portable.
    I would have probably approached it the same way you did. While likely not applicable, if you determine your data could have a row without a number value in the lname column, first pos, it could cause an issue. If that’s possible, you could use try_cast and it will return null if it cannot parse the column.

    Code:
    WITH FilteredUsers AS (
      SELECT userid, lname
      FROM [user]
      WHERE LEFT(lname, 1) BETWEEN '0' AND '9'
    )
    SELECT *
    FROM FilteredUsers
    WHERE TRY_CAST(userid AS INT) IS NOT NULL AND TRY_CAST(userid AS VARCHAR(5)) = lname;​
    Wayne

    Comment


      #3
      Hi Wayne,
      Thank you for responding.
      The userid column is 10 characters long, using zeros to left pad the id,
      so I trying to filter rows where userid '0000000245' and lname = '245'.

      trycast looks like an interesting function. I'm trying to figure out what the With FilteredUsers as does (Is it similar to mySql's <calculated value> as 'FilteredUsers'
      Gregg
      https://paiza.io is a great site to test and share sql code

      Comment


        #4
        I think I see what you are doing. One table I assume has the ID with leading zeros and the related table does not?
        I am completely unfamiliar with MYSQL. I probably need to learn it as it would get me away from express.
        The WITH FilteredUsers is basically a CTE - Common Table Expression. Basically it is just a syntax thing to keep it clean. In SQL, it would be like putting a calculation into a function and then calling that function or variable from another set of code.
        It becomes more efficient if you had another part of the query that needs to call the same records. It saves you from typing it over again and you can just call the CTE in your select.

        I am not a pro on it and end up fighting with dates and numbers alot... but I think you might be able to use CAST in this case as well. Maybe worth trying.

        Code:
        WITH FilteredUsers AS (
          SELECT
            userid,
            lname,
            -- Remove leading zeros from userid by converting it to an integer and back to string
            CAST(CAST(userid AS INT) AS VARCHAR(50)) AS stripped_userid,
            CAST(CAST(lname AS INT) AS VARCHAR(50)) AS stripped_lname
          FROM [user]
          WHERE LEFT(lname, 1) BETWEEN '0' AND '9'
        )
        SELECT *
        FROM FilteredUsers
        WHERE TRY_CAST(stripped_userid AS INT) IS NOT NULL AND stripped_userid = stripped_lname;
        ​

        Comment


          #5
          Originally posted by WayneH View Post
          ?
          I am completely unfamiliar with MYSQL. I probably need to learn it as it would get me away from express.

          If you or your customers have any need for MS365 integration then SQL Server or SQL Database is the right choice. You can easily integrate your application to almost any MS365 application for example using Power Automate. This may be a big advantage over MYSQL.

          Comment


            #6
            Thanks Wayne.
            Im going to persue this just because its not uncommon to
            run across mssql, but if you want
            to mess with mysql(including functions to make working with dates easier, just reach out. The date functions are easy on
            their own, but since i have a habit of forgetting of
            the format or the value comes first, I wrote my own functions that just need the value (ie: gl.today() gets 2023-10-05).
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              kkfin I thought microsoft provides various connectors to 3rd party products (like MySQL and X(formerly known as twitter).
              I still have to experiment with power automate
              Gregg
              https://paiza.io is a great site to test and share sql code

              Comment


                #8
                Originally posted by madtowng View Post
                kkfin I thought microsoft provides various connectors to 3rd party products (like MySQL and X(formerly known as twitter).
                I still have to experiment with power automate
                Yes they do but as i did put in my post in bold you can build easily with SQL Server. SQL Server connector has lot of prebuild triggers. With MYSQL you are totally on your own.

                Comment


                  #9
                  try this

                  SELECT u.userid, u.lname FROM [user] u JOIN (SELECT DISTINCT userid FROM [user] WHERE LEFT(lname, 1) BETWEEN '0' AND '9') d ON d.userid = CAST(u.lname AS INT)

                  Comment


                    #10
                    I have found ChatGPT very useful in learning more about SQL. For instance, I put the above query into it and got.

                    SELECT u.userid, u.lname FROM [user] u WHERE u.lname LIKE '[0-9]%';

                    The big thing with ChatGPT is learning how to write the questions. I started out getting responses that didn't quite fit, but you have to order it around a little bit, and be direct.

                    image.png


                    and for your original code:

                    SELECT userid, lname
                    FROM [user]
                    WHERE lname LIKE '[0-9]%' AND ISNUMERIC(userid) = 1 AND CAST(userid AS INT) = CAST(lname AS INT);

                    image.png​​

                    Comment


                      #11
                      Hi Russell,
                      Thanks to ms sql, I stumbled across having chatGPT "fix" my code.
                      I think this is an option I'm probably going to exploit a lot in the future.
                      Gregg
                      https://paiza.io is a great site to test and share sql code

                      Comment


                        #12
                        Originally posted by madtowng View Post
                        Hi Russell,
                        Thanks to ms sql, I stumbled across having chatGPT "fix" my code.
                        I think this is an option I'm probably going to exploit a lot in the future.
                        you will be amazed of how many AI brands are available, I use
                        • Perplexity AI.
                        • Google Bard AI.
                        • Chatsonic.
                        • GPT
                        • LILMAand

                        And so many other online tools, which can even do the entire app and deploy it for you with the best practise and security standards.
                        but at the end, it will not do these small details which human brains can achive!

                        Good luck Gregg :)

                        Comment


                          #13
                          Would you like to play a game?
                          In all seriousness, agree… ai is going to be revolutionary. Especially useful when we can start seeing it integrated into our code editor.
                          You do not have permission to view this gallery.
                          This gallery has 1 photos.

                          Comment


                            #14
                            Originally posted by WayneH View Post
                            Would you like to play a game?
                            In all seriousness, agree… ai is going to be revolutionary. Especially useful when we can start seeing it integrated into our code editor.
                            Indeed, it's true that AI greatly assists programmers. However, it's crucial to remember a fundamental aspect – AI is a product of human ingenuity. While this may delve into philosophical perspectives, my life experiences have shown that humans possess a complex spectrum of qualities, encompassing both greed and selflessness, intelligence and folly, goodness and malevolence. This inherent duality is woven into our design.

                            The key takeaway is that AI, despite its immense capabilities, will always harbor vulnerabilities. Beyond the obvious concerns of cybersecurity, we must acknowledge that its designers, being human, introduce potential weak points. There will invariably exist avenues to access and manipulate AI when circumstances demand it.

                            Also, do not forget networks, network, intranets, vpns, internet zones and intenet caching will always be over any application in the world.

                            Please take heed of these words.and mark it!

                            Comment


                              #15
                              how can anyone not like the wargames reference.
                              Gregg
                              https://paiza.io is a great site to test and share sql code

                              Comment

                              Working...
                              X