Usuário com melhor resposta
Agrupamento de string.. um help ai

Pergunta
-
Fala ai pessoal, tenho uma tabela assim:
NOME SOBRENOME EMAIL CEP CIDADE ESTADO A B C NULL NULL testando@hotmail.com NULL NULL NULL NULL NULL NULL NULL NULL testando@hotmail.com 24210200 NULL NULL S NULL NULL Carlos Silva testando@hotmail.com NULL Niteroi RJ NULL NULL NULL NULL NULL testando@hotmail.com NULL NULL NULL S S NULL NULL NULL testando@hotmail.com 24210200 NULL NULL NULL NULL NULL NULL NULL testando@hotmail.com 24210200 NULL NULL S NULL NULL Carlos Silva testando@hotmail.com NULL NULL NULL NULL S NULL NULL NULL testando@hotmail.com NULL NULL NULL S NULL NULL NULL NULL testando@hotmail.com NULL NULL RJ NULL NULL NULL
Será que com uma query eu consigo juntar todas as string.. o resultado que eu queria é assim:
NOME SOBRENOME EMAIL CEP CIDADE ESTADO A B C Carlos Silva testando@hotmail.com 24210200 Niteroi RJ S S NULL
haaa todas as colunas são string
desde já agradeço rapaziada...
- Editado RenaPVieira quarta-feira, 19 de setembro de 2012 19:53
Respostas
-
Renan, tente o codigo abaixo:
SELECT LTRIM(RTrim(ISNULL(NOME, '')))+ LTRIM(RTrim(ISNULL(SOBRENOME, '')))+ LTRIM(RTrim(ISNULL(EMAIL, '')))+ LTRIM(RTrim(ISNULL(CEP, '')))+ LTRIM(RTrim(ISNULL(CIDADE, '')))+ LTRIM(RTrim(ISNULL(ESTADO, '')))+ LTRIM(RTrim(ISNULL(A, '')))+ LTRIM(RTrim(ISNULL(B, '')))+ LTRIM(RTrim(ISNULL(C, ''))) AS LINHA FROM TABELA where NOME is not null and SOBRENOME is not null and EMAIL is not null and CEP is not null and CIDADE is not null and ESTADO is not null and A is not null and B is not null and C is not null
Alexandre Matayosi Conde Mauricio. Se esta sugestão for útil, por favor, classifique-a como útil. Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.
- Marcado como Resposta Harley Araujo sexta-feira, 21 de setembro de 2012 12:07
-
No SQL 2012 você tem a função CONCAT. Do 2012 pra baixo tem que ser "somando" os campos mesmo, com LTrim e RTrim.
Roberson Ferreira - Database Developer
Acesse: www.robersonferreira.com.br
Email: contato@robersonferreira.com.brSe esta sugestão for útil, por favor, classifique-a como útil.
Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.- Marcado como Resposta Harley Araujo sexta-feira, 21 de setembro de 2012 12:07
Todas as Respostas
-
Renan, voce quer juntar as strings ou não mostrar os campos nulos ?
Alexandre Matayosi Conde Mauricio. Se esta sugestão for útil, por favor, classifique-a como útil. Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.
-
Tenta isso:
SELECT
LTRIM(RTrim(ISNULL(NOME, '')))+REPLICATE(' ', 100 - LEN(LTRIM(RTrim(ISNULL(NOME, '')))))+
LTRIM(RTrim(ISNULL(SOBRENOME, '')))+REPLICATE(' ', 100 - LEN(LTRIM(RTrim(ISNULL(SOBRENOME, '')))))+
LTRIM(RTrim(ISNULL(EMAIL, '')))+REPLICATE(' ', 200 - LEN(LTRIM(RTrim(ISNULL(EMAIL, '')))))+
LTRIM(RTrim(ISNULL(CEP, '')))+REPLICATE(' ', 10 - LEN(LTRIM(RTrim(ISNULL(CEP, '')))))+
LTRIM(RTrim(ISNULL(CIDADE, '')))+REPLICATE(' ', 100 - LEN(LTRIM(RTrim(ISNULL(CIDADE, '')))))+
LTRIM(RTrim(ISNULL(ESTADO, '')))+REPLICATE(' ', 2 - LEN(LTRIM(RTrim(ISNULL(ESTADO, '')))))+
LTRIM(RTrim(ISNULL(A, '')))+REPLICATE(' ', 1 - LEN(LTRIM(RTrim(ISNULL(A, '')))))+
LTRIM(RTrim(ISNULL(B, '')))+REPLICATE(' ', 1 - LEN(LTRIM(RTrim(ISNULL(B, '')))))+
LTRIM(RTrim(ISNULL(C, '')))+REPLICATE(' ', 1 - LEN(LTRIM(RTrim(ISNULL(C, ''))))) AS LINHA
FROM TABELA
OU
SELECT
LTRIM(RTrim(ISNULL(NOME, '')))+
LTRIM(RTrim(ISNULL(SOBRENOME, '')))+
LTRIM(RTrim(ISNULL(EMAIL, '')))+
LTRIM(RTrim(ISNULL(CEP, '')))+
LTRIM(RTrim(ISNULL(CIDADE, '')))+
LTRIM(RTrim(ISNULL(ESTADO, '')))+
LTRIM(RTrim(ISNULL(A, '')))+
LTRIM(RTrim(ISNULL(B, '')))+
LTRIM(RTrim(ISNULL(C, ''))) AS LINHA
FROM TABELA
- Sugerido como Resposta darkdoni quarta-feira, 19 de setembro de 2012 21:08
-
-
Renan, tente o codigo abaixo:
SELECT LTRIM(RTrim(ISNULL(NOME, '')))+ LTRIM(RTrim(ISNULL(SOBRENOME, '')))+ LTRIM(RTrim(ISNULL(EMAIL, '')))+ LTRIM(RTrim(ISNULL(CEP, '')))+ LTRIM(RTrim(ISNULL(CIDADE, '')))+ LTRIM(RTrim(ISNULL(ESTADO, '')))+ LTRIM(RTrim(ISNULL(A, '')))+ LTRIM(RTrim(ISNULL(B, '')))+ LTRIM(RTrim(ISNULL(C, ''))) AS LINHA FROM TABELA where NOME is not null and SOBRENOME is not null and EMAIL is not null and CEP is not null and CIDADE is not null and ESTADO is not null and A is not null and B is not null and C is not null
Alexandre Matayosi Conde Mauricio. Se esta sugestão for útil, por favor, classifique-a como útil. Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.
- Marcado como Resposta Harley Araujo sexta-feira, 21 de setembro de 2012 12:07
-
No SQL 2012 você tem a função CONCAT. Do 2012 pra baixo tem que ser "somando" os campos mesmo, com LTrim e RTrim.
Roberson Ferreira - Database Developer
Acesse: www.robersonferreira.com.br
Email: contato@robersonferreira.com.brSe esta sugestão for útil, por favor, classifique-a como útil.
Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.- Marcado como Resposta Harley Araujo sexta-feira, 21 de setembro de 2012 12:07