Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have this query that i want to concat the values in between the "()". How can i do it correctly?

Sql query:

C#
string SQL = "SELECT a.id_veiculo, a.id_empresa, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, a.ncartao, (a.data + a.hora) as 'Entrada', a.obs,a.sector, (b.data + b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa; ";



EDIT:

C#
string SQL = "SELECT a.id_veiculo, a.id_empresa, a.ncartao, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, CONCAT(a.data,a.hora) as 'Entrada',a.sector,a.obs, CONCAT(b.data,b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa; ";

This string works fine, but i have the value in it like "2016-03-0109:58:00" and i want it to be like so "2016-03-01 / 09:58:00"

What I have tried:

Tryied to replicate this string with the CONCAT where i wanted to combine data, like so:

string SQL = "SELECT a.id_veiculo, a.id_empresa, a.nome_condutor, a.empresa_visitante, a.empresa_visitar, a.visitado, a.ncartao, CONCAT(a.data, a.hora) as 'Entrada', a.obs,a.sector, (b.data, b.hora) as 'Saida' FROM entradas a LEFT OUTER JOIN saidas b ON a.data = b.data AND a.hora = b.hora and a.sector WHERE id_empresa = @tabempresa;
Posted
Updated 1-Mar-16 5:06am
v2
Comments
CHill60 1-Mar-16 10:08am    
What is wrong with what you have?
Scribling Doodle 1-Mar-16 10:17am    
Check this printscreen, that's what i'm trying to do. https://gyazo.com/56c1afc8aa9436a58a833c133dc3e44b

I want to "CONCAT" the columns data and hora to a column called "entrada" and data1 and hora1 to "saida"

1 solution

According to the documentation[^], the CONCAT function accepts multiple string arguments. You just need to pass the separator in between the fields:
SQL
CONCAT(a.data, ' / ', a.hora)
 
Share this answer
 
Comments
Scribling Doodle 1-Mar-16 11:16am    
Alright, thanks dude! ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900