SQL Query to Compare Two Strings Last Updated : 14 Sep, 2021 Comments Improve Suggest changes Like Article Like Report SQL stands for Structured Query Language. It is used to communicate with the database. There are some standard SQL commands like 'select', 'delete', 'alter' etc. To compare two strings in SQL Server, there is no direct way. In this article, we will learn how to compare two strings in an MS SQL server and we will provide some examples. A string function is a function that takes a string value as an input regardless of the data type of the returned value. In SQL Server, there are many built-in string functions that can be used by developers. We can compare strings by using the IF-ELSE statement. Syntax: IF Boolean_expression { sql_statement | statement_block } [ ELSE { sql_statement | statement_block } ] Declare variable:We can declare variables easily by using the keyword DECLARE before the variable name. By default, the local variable starts with @. Syntax: DECLARE @variable_name datatype; Set values to the variable:We can assign value to the variables using the SET keyword. Syntax: SET @variable_name; Example 1: Query: DECLARE @Name1 VARCHAR(30), @Name2 VARCHAR(20); Set @Name1='geeks'; Set @Name2='geeks'; If @Name1=@Name2 Select 'match' else Select 'not match';Output: The above example shows the string comparison and returns the result as a 'match' because both strings are the same. Example 2: Query: DECLARE @Name1 VARCHAR(30), @Name2 VARCHAR(20); Set @Name1='geeks'; Set @Name2='geeksforgeeks'; If @Name1=@Name2 Select 'match' else Select 'not match';Output: The above example shows the string comparison and returns the result as a 'not match' because both strings are not the same. Comment More infoAdvertise with us Next Article SQL Query to Compare Two Strings romy421kumari Follow Improve Article Tags : SQL Blogathon Blogathon-2021 SQL-Query Similar Reads SQL Query to Compare Two Dates In SQL, dates are complicated for newbies, since while working with the database, the format of the date in the table must be matched with the input date in order to insert. In various scenarios instead of date, DateTime (time is also involved with date) is used. Here we will see, SQL Query to compa 2 min read SQL Query to Match Any Part of String It is used for searching a string or a sub-string to find a certain character or group of characters from a string. We can use the LIKE Operator of SQL to search sub-strings. The LIKE operator is used with the WHERE Clause to search a pattern in a string of columns. The LIKE operator is used in conj 3 min read How to Compare Two Queries in SQL Queries in SQL :A query will either be an invitation for data results from your info or for action on the info, or each. a question will provide you with a solution to a straightforward question, perform calculations, mix data from totally different tables, add, change, or delete data from info. Cre 2 min read How to Compare Strings in C#? A string is a collection of characters and is used to store plain text. Unlike C or C++, a string in C# is not terminated with a null character. The maximum size of a string object depends on the internal architecture of the system. A variable declared followed by "string" is actually an object of s 13 min read SQL Query to Compare Results With Today's Date In SQL, comparing results with today's date is a powerful tool for filtering data, managing schedules, including managing tasks, appointments and performing time-sensitive analysis. By using SQL's GETDATE() function we can easily perform this comparison. The ability to filter records based on date c 4 min read Compare SQL Server Results of Two Queries SQL Server is a versatile database, and it is the most used Relational Database that is used across many software industries. In this article, let us see the comparison of SQL Server Results of Two Queries briefly. By using Azure Data Studio, let us see the concepts by starting with creating the dat 5 min read SQL Query to Get Only Numbers From a String As we know in an SQL database we can insert any type of data. Sometimes in the productions server, the data gets corrupted by two or more rows being merged and being saved in a column. In that case, we can extract the numeric part from that string and save it again. So in this article, we will learn 2 min read How to Compare Time in MS SQL Server? To compare time in MS SQL Server, use the comparison operators (=,<,>, etc.). In this article, we will be making use of the Microsoft SQL Server as our database. and comparing times using both pre-defined dates and the current date and time with the GETDATE() function.First, let's create a dat 3 min read PL/SQL Strings We will learn several types of strings, the syntax for declaring a string variable, and then utilizing it in a PL/SQL code block. In PL/SQL, a string is a sequence of characters with an optimal size parameter. Strings are sequences of characters, and PL/SQL provides a rich set of functions and opera 6 min read How to compare columns in two different tables in SQL Here we are going to see how we can compare the columns of two different tables in SQL. We will be taking a few examples to see how we can do this in different ways. Overview :In this, we will understand overview of SQL query for required operation to perform How to compare columns in two different 4 min read Like