Coding Tips

Tuesday, June 2, 2009

Split a string into records in SQL Server 2005

This function will accept a string and a delimiter and returns you the results as records.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- ======================================
-- Description: Returns as a record set .
-- The input can be a string which is separated by any delimiter
-- ======================================
CREATE FUNCTION [dbo].[SplitStr]
(
@InpString
varchar(2500),
@Delimiter
char(1)
)
RETURNS @tmptable
TABLE (items varchar(2500))
AS
BEGIN
Declare
@indx int
Declare
@StrPart varchar(2500)

Select @indx = 1
if len(@InpString)<1 or @InpString is null RETURN

While
@indx!= 0
Begin
set
@indx = charindex(@Delimiter,@InpString)
if @indx!=0
set @StrPart = left(@InpString,@indx - 1)
else
set
@StrPart = @InpString

if(len(@StrPart)>0)
insert into @tmptable(Items) values(@StrPart)

set @InpString = right(@InpString,len(@InpString) - @indx)
if len(@InpString) = 0 break
End
return

END


Monday, June 30, 2008

ASCII Table

ASCII table is needed for processing character based operations in any programming language.

ASCII - American Standard Code for Information Interchange is a character encoding based on the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that work with text.  

You can find in the below screen shots the decimal values and its equivalent hexadecimal values with character codes.

1) Non Printable ASCII Characters
2) Printable ASCII Characters
3) Extended ASCII Characters