Click here to Skip to main content
15,892,072 members
Home / Discussions / Database
   

Database

 
AnswerRe: ho to retrieve a list of dependants [modified] Pin
Niladri_Biswas29-Jun-09 23:59
Niladri_Biswas29-Jun-09 23:59 
GeneralRe: ho to retrieve a list of dependants Pin
Anoop Brijmohun5-Jul-09 20:16
Anoop Brijmohun5-Jul-09 20:16 
QuestionConvert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 0:31
professionalVimalsoft(Pty) Ltd29-Jun-09 0:31 
AnswerRe: Convert String and Sort the the Intergers in a String ASC Pin
Aman Bhullar29-Jun-09 2:20
Aman Bhullar29-Jun-09 2:20 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 2:25
professionalVimalsoft(Pty) Ltd29-Jun-09 2:25 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Aman Bhullar29-Jun-09 3:06
Aman Bhullar29-Jun-09 3:06 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 3:21
professionalVimalsoft(Pty) Ltd29-Jun-09 3:21 
AnswerRe: Convert String and Sort the the Intergers in a String ASC [modified] Pin
Niladri_Biswas29-Jun-09 5:45
Niladri_Biswas29-Jun-09 5:45 
Hi,

The steps are:

1) Use a table valued split function to split the comma delimited strings

2) Then sort the table values

3) Loop thru each values of the table and make a customised delimited

string .

The above steps are depicted below

STEP 1:

The split function goes like this


 -- Created by NILADRI BISWAS
           ALTER FUNCTION [dbo].[fnSplit] 
           (@oldstring as varchar(100),@delimeter as varchar(1))
           RETURNS @mytab table(counter int,stringval varchar(100)) 
           AS
            Begin 
		
		Declare @newstring as varchar(100)
		Declare @pos as int
		Declare @i as int
		Declare @c as int	

		set @newstring = '';		
		set @i = 1
		set @c = 0

		set @pos = CHARINDEX(@delimeter, @oldstring) 

		WHILE (@i != 0)

			Begin

				set @c = @c +1
				insert into @mytab(counter,stringval) values(@c,@newstring + Substring(@oldstring,0, @pos))

				
				set @oldstring = Substring(@oldstring,@pos+1,len(@oldstring))

				set @pos = CHARINDEX(@delimeter, @oldstring)

				set @i = @pos;
				if (@i = 0)
                Begin
                    set @i = 0;
						set @c = @c +1
                
					insert into @mytab(counter,stringval) values(@c,@newstring + @oldstring)
					
                End

			End

			return 

End



Create a stored proc like this


-- Created by NILADRI BISWAS
       ALTER PROCEDURE dbo.SortedList
	-- Add the parameters for the stored procedure here
	(@DelimitedValues AS VARCHAR(50))
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	DECLARE @OUTPUT VARCHAR(30)
	DECLARE @TEMPOUTPUT VARCHAR(30)
    
	SET @OUTPUT = ''
	SET @TEMPOUTPUT = ''

	DECLARE @MYCURSOR CURSOR
	SET @MYCURSOR = CURSOR FOR


STEP 2:
SELECT STRINGVAL FROM dbo.fnSplit(@DelimitedValues,',')
	ORDER BY RIGHT(REPLICATE('0', 11) + stringval, 10)


STEP 3:
OPEN @MYCURSOR
	FETCH NEXT
	FROM @MYCURSOR INTO @TEMPOUTPUT
	WHILE @@FETCH_STATUS = 0

	BEGIN
	SET @OUTPUT =  @OUTPUT + @TEMPOUTPUT + ','

	FETCH NEXT
	FROM @MYCURSOR INTO @TEMPOUTPUT
	END
	CLOSE @MYCURSOR
	DEALLOCATE @MYCURSOR


SET @OUTPUT	 = SUBSTRING(@OUTPUT,0,LEN(@OUTPUT))

	PRINT @OUTPUT	
END




Hope this helps
Smile | :)

Niladri Biswas

modified on Monday, June 29, 2009 11:52 AM

GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 5:48
professionalVimalsoft(Pty) Ltd29-Jun-09 5:48 
GeneralRe: Convert String and Sort the the Intergers in a String ASC [modified] Pin
Niladri_Biswas29-Jun-09 5:55
Niladri_Biswas29-Jun-09 5:55 
GeneralRe: Convert String and Sort the the Intergers in a String ASC Pin
Vimalsoft(Pty) Ltd29-Jun-09 5:56
professionalVimalsoft(Pty) Ltd29-Jun-09 5:56 
QuestionProblem with joining tables in MSAccess. Pin
A k ch28-Jun-09 19:32
A k ch28-Jun-09 19:32 
AnswerRe: Problem with joining tables in MSAccess. Pin
riced28-Jun-09 22:44
riced28-Jun-09 22:44 
GeneralRe: Problem with joining tables in MSAccess. Pin
A k ch28-Jun-09 23:04
A k ch28-Jun-09 23:04 
AnswerRe: Problem with joining tables in MSAccess. Pin
Niladri_Biswas28-Jun-09 23:07
Niladri_Biswas28-Jun-09 23:07 
GeneralRe: Problem with joining tables in MSAccess. Pin
A k ch28-Jun-09 23:33
A k ch28-Jun-09 23:33 
GeneralRe: Problem with joining tables in MSAccess. Pin
riced29-Jun-09 0:43
riced29-Jun-09 0:43 
GeneralRe: Problem with joining tables in MSAccess. Pin
A k ch29-Jun-09 1:00
A k ch29-Jun-09 1:00 
QuestionFLOAT vs NUMERIC for financial transaction Pin
devvvy28-Jun-09 15:23
devvvy28-Jun-09 15:23 
AnswerRe: FLOAT vs NUMERIC for financial transaction Pin
Niladri_Biswas28-Jun-09 16:37
Niladri_Biswas28-Jun-09 16:37 
GeneralRe: FLOAT vs NUMERIC for financial transaction Pin
devvvy28-Jun-09 16:41
devvvy28-Jun-09 16:41 
GeneralRe: FLOAT vs NUMERIC for financial transaction Pin
Niladri_Biswas28-Jun-09 16:44
Niladri_Biswas28-Jun-09 16:44 
GeneralRe: FLOAT vs NUMERIC for financial transaction Pin
devvvy28-Jun-09 16:57
devvvy28-Jun-09 16:57 
GeneralRe: FLOAT vs NUMERIC for financial transaction Pin
Niladri_Biswas28-Jun-09 17:33
Niladri_Biswas28-Jun-09 17:33 
GeneralRe: FLOAT vs NUMERIC for financial transaction Pin
Niladri_Biswas28-Jun-09 22:30
Niladri_Biswas28-Jun-09 22:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.