Você está na página 1de 3

SELECT CASE WHEN clcgc > '0' THEN CAST(CLCGC AS varchar(14)) ELSE CONVERT(varchar(14), CLcpf) END AS Expr1, case

when ascii(substring(CLRAZAO,len(CLRAZAO), 1)) = 0 then CONVERT(VARCHAR(4 0),substring(CLRAZAO, 1, LEN(CLRAZAO) - 1 ) ) ELSE CONVERT(VARCHAR(40),substring(CLRAZAO, 1, LEN(CLRAZAO) ) ) END AS expr2 , CASE WHEN cll = '' THEN 'Rua' else case when ascii(substring(CLL,len(CLL), 1)) = 0 then CONVERT(VARCHAR(03),subst ring(CLL, 1, LEN(CLL) - 1 ) ) ELSE CONVERT(VARCHAR(03),substring(CLL, 1, LEN(CLL) ) ) end END AS expr3 , case when ascii(substring(CLEND,len(CLEND), 1)) = 0 then CONVERT(VARCHAR(30),' ' + substring(CLEND, 1, LEN(CLEND) - 1 ) + ',' ) ELSE CONVERT(VARCHAR(30),' ' + substring(CLEND, 1, LEN(CLEND) ) + ',' ) END AS expr4 , case when ascii(substring(CLNUM,len(CLNUM), 1)) = 0 then CONVERT(VARCHAR(05),s ubstring(CLNUM, 1, LEN(CLNUM) - 1 ) ) ELSE CONVERT(VARCHAR(05),substring(CLNUM, 1, LEN(CLNUM))) END AS expr5 , CONVERT(varchar(08), CLCEP) AS Expr3, case when ascii(substring(CLBAIRRO,len(CLBAIRRO), 1)) = 0 then CONVERT(VARCHAR (15),substring(CLBAIRRO, 1, LEN(CLBAIRRO) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLBAIRRO, 1, LEN(CLBAIRRO))) END AS expr6 , case when ascii(substring(CLCIDADE,len(CLCIDADE), 1)) = 0 then CONVERT(VARCHAR (15),substring(CLCIDADE, 1, LEN(CLCIDADE) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLCIDADE, 1, LEN(CLCIDADE))) END AS expr7 , case when ascii(substring(CLUF,len(CLUF), 1)) = 0 then CONVERT(VARCHAR(15),sub string(CLUF, 1, LEN(CLUF) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLUF, 1, LEN(CLUF))) END AS expr8 FROM dbo.HT_DBAU001_DCLIENTE

WHERE (CLDTINCLUSAO > CONVERT(DATETIME, GETDATE() - 300, 102)) AND (CLATIV = 'DISTRIBUIDOR' OR CLATIV = 'REVENDEDOR/SALO BELEZA')

================= SELECT CASE WHEN clcgc > '0' THEN case when ascii(substring(CLCGC,len(CLCGC), 1)) = 0 then CONVERT(VARCHAR (14),substring(CLCGC, 1, LEN(CLCGC) - 1 ) ) ELSE CONVERT(VARCHAR(14),substring(CLCGC, 1, LEN(CLCGC) ) ) end ELSE case when ascii(substring(CLCPF,len(CLCPF), 1)) = 0 then CONVERT(VARCHAR( 14),substring(CLCPF, 1, LEN(CLCPF) - 1 ) ) ELSE CONVERT(VARCHAR(14),substring(CLCPF, 1, LEN(CLCPF) ) ) END END AS Expr1, case when ascii(substring(CLRAZAO,len(CLRAZAO), 1)) = 0 then CONVERT(VARCHAR(4 0),substring(CLRAZAO, 1, LEN(CLRAZAO) - 1 ) ) ELSE CONVERT(VARCHAR(40),substring(CLRAZAO, 1, LEN(CLRAZAO) ) ) END AS expr2 , CASE WHEN cll = '' THEN 'Rua' else case when ascii(substring(CLL,len(CLL), 1)) = 0 then CONVERT(VARCHAR(03),subst ring(CLL, 1, LEN(CLL) - 1 ) ) ELSE CONVERT(VARCHAR(03),substring(CLL, 1, LEN(CLL) ) ) end END AS expr3 , case when ascii(substring(CLEND,len(CLEND), 1)) = 0 then CONVERT(VARCHAR(30),' ' + substring(CLEND, 1, LEN(CLEND) - 1 ) + ',' ) ELSE CONVERT(VARCHAR(30),' ' + substring(CLEND, 1, LEN(CLEND) ) + ',' ) END AS expr4 , case when ascii(substring(CLNUM,len(CLNUM), 1)) = 0 then CONVERT(VARCHAR(05),s ubstring(CLNUM, 1, LEN(CLNUM) - 1 ) ) ELSE CONVERT(VARCHAR(05),substring(CLNUM, 1, LEN(CLNUM))) END AS expr5 , CONVERT(varchar(08), CLCEP) AS Expr3, case when ascii(substring(CLBAIRRO,len(CLBAIRRO), 1)) = 0 then CONVERT(VARCHAR (15),substring(CLBAIRRO, 1, LEN(CLBAIRRO) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLBAIRRO, 1, LEN(CLBAIRRO))) END AS expr6 , case when ascii(substring(CLCIDADE,len(CLCIDADE), 1)) = 0 then CONVERT(VARCHAR (15),substring(CLCIDADE, 1, LEN(CLCIDADE) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLCIDADE, 1, LEN(CLCIDADE))) END AS expr7 ,

case when ascii(substring(CLUF,len(CLUF), 1)) = 0 then CONVERT(VARCHAR(15),sub string(CLUF, 1, LEN(CLUF) - 1 ) ) ELSE CONVERT(VARCHAR(15),substring(CLUF, 1, LEN(CLUF))) END AS expr8 FROM dbo.HT_DBAU001_DCLIENTE

WHERE (CLDTINCLUSAO > CONVERT(DATETIME, GETDATE() - 300, 102)) AND (CLATIV = 'DISTRIBUIDOR' OR CLATIV = 'REVENDEDOR/SALO BELEZA')