Check Language in SQL Server
In SQL Server, you can check the language of a string using the LANGID
function or the PARSENAME
function. The LANGID
function returns the language ID of a string, while the PARSENAME
function returns the language name.
Syntax:
-- Using LANGID function
SELECT LANGID({string}) AS LanguageID; -- Using PARSENAME function
SELECT PARSENAME({string}, 1) AS LanguageName;
Example 1: Check Language using LANGID
Let's say we have a table named Customers
with a column named Address
, and we want to check the language of the address.
Table Structure:
CREATE TABLE Customers ( CustomerID int, Name varchar(50), Address nvarchar(100) );
Sample Data:
INSERT INTO Customers (CustomerID, Name, Address) VALUES (1, 'John Doe', '123 Main St, New York, USA'), (2, 'Jean Dupont', '12 Rue de la Paix, Paris, France'), (3, 'Pedro Sanchez', 'Calle de Alcalá, 12, Madrid, España');
Check Language:
SELECT Name, Address, LANGID(Address) AS LanguageID FROM Customers;
Result:
Name | Address | LanguageID |
---|---|---|
John Doe | 123 Main St, New York, USA | 1033 |
Jean Dupont | 12 Rue de la Paix, Paris, France | 1036 |
Pedro Sanchez | Calle de Alcalá, 12, Madrid, España | 1034 |
The language IDs returned are:
- 1033: English (United States)
- 1036: French (France)
- 1034: Spanish (Spain)
Example 2: Check Language using PARSENAME
Let's use the same table and data as before, but this time we'll use the PARSENAME
function to get the language name.
Check Language:
SELECT Name, Address, PARSENAME(Address, 1) AS LanguageName FROM Customers;
Result:
Name | Address | LanguageName |
---|---|---|
John Doe | 123 Main St, New York, USA | English |
Jean Dupont | 12 Rue de la Paix, Paris, France | French |
Pedro Sanchez | Calle de Alcalá, 12, Madrid, España | Spanish |