SQL – CAST() / CONCAT()

SQL – CAST() / CONCAT()

Hey all, here’s another conversion tip. In our project, Excel can join the contents of two fields together by using the following:

=(A1)&(B1)

In this example, we will join 2 values together. Lets say 10 is in A1 and 33 is in B1. So our code will be:

=(10)&(33)

In MSSQL, this can be done using the CAST() function.

SET JoinedValue = CAST (([Field1] AS VARCHAR(10)) + CAST ( [Field2])AS VARCHAR(10))

This will give us [ 1033 ] as a result.

Now in MySQL, the same can be achieved by using the CONCAT() Function:

SET JoinedValue = CONCAT (`Field1` , `Field2`)

This will give us the same result of “1033”

4 thoughts on “SQL – CAST() / CONCAT()

  • Wow, this paragraph is pleasant, my sister is analyzing these things, thus I am going to tell her.| Ivory Hubert Shreeves

  • Hey there! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked
    hard on. Any suggestions?

    My website :: buy CBD

    1. Hey Darla! Thanks for checking our site out and your question! Yes even we are constantly fending off hackers.
      Depending on what you are using for your website (assuming WordPress) there are some great free and paid options for website security
      Here is a link to 8 options: https://wpforms.com/best-wordpress-security-plugins/

      One of the best security measures you can implement is 2 factor authentication. It requires a person to use a username and password, and then an additional security step; either using an authenticator token (Microsoft / Google / Authy) or texting a code to your cellphone, that must be entered to login.

      We will add a tech blog writeup on 2fa soon so check back for more details!

  • Comments are closed.