Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/10/2014, 10:05
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 4 meses
Puntos: 774
Respuesta: Separar cadena de caracteres con Store procedure

Código SQL:
Ver original
  1. /****** Object:  UserDefinedFunction [dbo].[SplitApplication]    Script Date: 10/19/2010 15:12:35 ******/
  2. SET ANSI_NULLS ON
  3. GO
  4.  
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7.  
  8. CREATE FUNCTION [dbo].[SplitApplication](@applicationid VARCHAR(2000))
  9.  
  10. RETURNS @RtnValue TABLE
  11. (
  12. Id INT IDENTITY(1,1),
  13. DATA nvarchar(100)
  14. )
  15. AS
  16. BEGIN
  17. DECLARE @Cnt INT, @SplitOn nvarchar(5)
  18. SET @SplitOn = '##'
  19. SET @Cnt = 1
  20.  
  21. While (Charindex(@SplitOn,@applicationid)>0)
  22. BEGIN
  23. INSERT INTO @RtnValue (DATA)
  24. SELECT
  25. DATA = ltrim(rtrim(SUBSTRING(@applicationid,1,Charindex(@SplitOn,@applicationid)-1)))
  26.  
  27. SET @applicationid = SUBSTRING(@applicationid,Charindex(@SplitOn,@applicationid)+1,len(@applicationid))
  28. SET @Cnt = @Cnt + 1
  29. END
  30.  
  31. INSERT INTO @RtnValue (DATA)
  32. SELECT DATA = ltrim(rtrim(@applicationid))
  33.  
  34. RETURN
  35. END
  36.  
  37. GO
  38.  
  39.  
  40. how TO USE :
  41.  
  42. SELECT * FROM TABLE WHERE DATA IN (
  43.  
  44. SELECT * FROM SplitApplication('[email protected]##Receive;vlizarralde@argos .com.co##Receive;[email protected]##Receive;ja [email protected]##Receive;[email protected]## Receive;[email protected]##Receive, Deliver;[email protected]##Receive, Deliver;[email protected]')
  45. )

quizas esto te sirva
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me