Skip to main content

Posts

Showing posts from 2015

Coverting comma separated string to table in sql server

Sometimes we need to take multiple numbers/string paramter input in a single field of Crystal report. So we can manage it like user will give all the number in a single field and we need to return as a table so that we can use it IN paramter. Input: 2132,1231333,5555,321 Output: 2132 1231333 5555 321 -------------------------Function definition-------------------- CREATE FUNCTION [dbo].[StringToTable] (  @psCSString VARCHAR(8000) ) RETURNS @otTemp TABLE(sID VARCHAR(20)) AS BEGIN  DECLARE @sTemp VARCHAR(10)  WHILE LEN(@psCSString) > 0  BEGIN   SET @sTemp = LEFT(@psCSString, ISNULL(NULLIF(CHARINDEX(',', @psCSString) - 1, -1),                     LEN(@psCSString)))   SET @psCSString = SUBSTRING(@psCSString,ISNULL(NULLIF(CHARINDEX(',', @psCSString), 0),                                LEN(@psCSString)) + 1,...