Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. CREATE FUNCTION [dbo].[formatarCNPJCPF] (@CnpjCpf char(14))
  2. RETURNS CHAR(18)
  3. AS
  4. BEGIN
  5. DECLARE @retorno VARCHAR(18)
  6.  
  7. IF LEN(@CnpjCpf)= 14
  8. --CNPJ
  9. BEGIN
  10. SET @retorno = substring(@CnpjCpf ,1,2) + '.' + substring(@CnpjCpf ,3,3) + '.' + substring(@CnpjCpf ,6,3) + '/' + substring(@CnpjCpf ,9,4) + '-' + substring(@CnpjCpf ,13,2)
  11. END
  12. ELSE
  13. --CPF
  14. BEGIN
  15. SET @retorno = substring(@CnpjCpf ,1,3) + '.' + substring(@CnpjCpf ,4,3) + '.' + substring(@CnpjCpf ,7,3) + '-' + substring(@CnpjCpf ,10,2)
  16. END
  17. RETURN @retorno
  18. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement