Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Avoid Concat function in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 585
    Comment on it

    While writing queries in stored procedures we manipulate with the string data type columns in which concatenating string is very common.

     

    So we all are very familiar with the function CONCAT provided by the SQL Server for joining/merging strings used in the SQL queries and stored procedures.

     

    Using this function we can do the concatenation very easily .

     

    -- For merging two columns
    
    SELECT CONCAT(FirstName,LastName) FROM [EMPLOYEE]
    
    
    
    -- For merging three columns
    
    SELECT CONCAT(FirstName,MiddleName,LastName) FROM [EMPLOYEE]

     

    This is easy to use function while merging strings but when we deploy our code on servers the function not supported properly and your code will show error while execution and you try to find out in the application part where the problem is.

    Server may contain the older version of the SQL server where this function is not supported.

    So instead of facing this situation we can use the general way to merge the strings in the SQL query which is universal for all SQL versions later or older.

     

    SELECT ([FirstName] + ' ' + [LastName]) AS [CreatedBy] IN EMPLOYEE

    This will get executed and merge the string whenever we want and in any version of SQL Server.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: