Run query that concatenates parameters (@p) in Firebird

2

I need to execute a query where the value to be concatenated should be passed as a parameter to the query.

SELECT t.id || @p || t.nome FROM Test t;

But when you run this query it returns the following error: Dynamic SQL Error.

In MySQL, this idea works as follows:

SELECT CONCAT(t.id, @p, t.nome) FROM Test t; 

I wonder if there is any way to do this type of concatenation in Firebird? For what I noticed the || operator is what causes this problem when a parameter is used.

  

Obs1: The value to be concatenated as a separator must be passed by parameter.

     

Obs2: I know that if I do the concatenation of the value in the query this works, getting the query to be executed this way: select t.id || 'stringparaseparar' || t.nome from Test t; , but in my case as mentioned above it is necessary that this value be passed by parameter. Ex: set @p = 'stringparaseparar'.

To better clarify the reason for this need, please follow this other question that describes the source of this problem.

    
asked by anonymous 03.09.2014 / 13:34

4 answers

1

In this case you should do a cast parameter for varchar :

SELECT t.id || cast(:p as varchar(10)) || t.nome FROM Test t;
    
09.10.2014 / 21:08
-1

You should do this:

SELECT t.id || :p || t.nome FROM Test t;

and not:

SELECT t.id || @p || t.nome FROM Test t;
    
03.09.2014 / 14:09
-1

I do not know if I understood your question perfectly, but come on.

Table: Product

Code | Contact Us | Complement 1 | Pencils | black 2 | Pen | Blue

 Select Codigo, Nome, Complemento,  Nome|| ' COR' || Complemento as TudoJunto from Produto

Result:

1 | Pencils | Black | Lapis Color Black

2 | Pen | Blue | Pen COLOR Blue

If not, post a comment I edit here.

    
04.09.2014 / 15:03
-1

For you to test this in IBEXPERT or even use within your application you have to do a query of a SOTED PROCEDURE you have to pass to a STORED PROCEDURE

Your Source Select Command for a procedure looks like this:

Select cidade From Busca_CEP("17504110")
create or alter procedure BUSCA_CEP (
    PCEP integer)
returns (
    cidade varchar(60)))
as
begin
   Select CEP.cidade From CEP into :cidade;
end

I think this solves your problem ...

    
21.09.2014 / 20:44