I'd like to ask how to concatenate strings in SQL (Delphi XE2)

I'd like to ask how to concatenate strings in SQL (Delphi XE2)
for example a field X from table A is composed from two sub-field Y and Z from table B. I tried :
select * from A where X= (select Y||Z from B) it didn't work like this, neither with CONCAT( Y, Z) or COCATENATE.

X= ABCD , Y= AB, Z= CD for example

any help from experts!! 
Thanks in advance.

Comments

  1. This seems more like a SQL query question than something specific to Delphi.  You haven't said which RDBMS product are using (SQL Server, MySQL, PGSQL, etc.), nor have you expanded upon, "it didn't work".  Are you getting an error message or just not the results you expect?

    Once you provide these details, you may find more people able to provide useful assistance.

    ReplyDelete
  2. Try Y + Z. Also, if your subquery returns more than one result you'll likely get an error.

    ReplyDelete
  3. Instead of  ||   try the   +  (plus sign)

    ReplyDelete
  4. It may be the answer 

    mysql> select X from A, B where A.X = CONCAT(B.Y, B.Z);
    +--------+
    | X          |
    +--------+
    | javascript |
    +--------+
    1 row in set (0.00 sec)

    ReplyDelete

Post a Comment