|
|
|
Saturday, 28 January 2012 01:36 |
// function for getting comma seperated values in sql server
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
-- This function splits a variable-length parameter array (actually a string
-- with comma as a delimiter) and stored the values into the table.
-- CHARINDEX() function is used to identify the position of the first delimiter
-- in the text and SUBSTRING() function is used to set the 'element' column.
ALTER FUNCTION [dbo].[GetCSVValues](
@string varchar(550) -- '1,2,3,5,6,7'
)
RETURNS @table TABLE(element int)
AS
BEGIN
DECLARE @tempvarchar(550),
@delimPos AS tinyint
SET @delimPos = 0
SET @temp= LTRIM(RTRIM(@string))
WHILE CHARINDEX(',',@temp) > 0
BEGIN
SET @delimPos = CHARINDEX(',',@temp)
INSERT INTO @table(element) VALUES (CAST((LEFT(@temp,@delimPos-1)) AS smallint))
SET @temp= RTRIM(LTRIM(SUBSTRING(@temp,@delimPos+1,LEN(@temp)-@delimPos)))
END
INSERT INTO @table(element) VALUES (CAST((@temp) AS smallint))
RETURN
END
 Read more: |
|
|
Friday, 27 January 2012 11:44 |
// how to access server side function using javascript
protected string ServerFunciton()
{
string toppltip= string.Format("I am a server side function");
return tooltip;
}
 Read more: |
|
Monday, 26 December 2011 23:53 |
In SQL Server used Cast or Convert function to Format DateTime value or column into a specific date format.Both function are used to convert datetime to varchar or string.
CAST(expression as data_type)
Let's convert current date time to varchar
select cast(getdate() as varchar)
CONVERT function is used to change or convert the DateTime formats.By using convert function you can get only Date part or only Time part from the datetime.
CONVERT Function Syntax:
CONVERT(data_type,expression,date Format style)
 Read more: |
|
|
Wednesday, 21 December 2011 01:21 |
I had a need to count the number of times a certain string appeared within a column in a SQL table. I came up with this simple function that may be of use to others.
-- Setup: Create a blank function if none exists. This allows us to
-- rerun this single script each time we modify this function
IF NOT EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'dbo.com_CountString')
AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
EXEC dbo.sp_executesql @statement = N'create function dbo.com_CountString() RETURNS INT AS BEGIN RETURN '''' END'
go
-- Create the actual function
/*====================================================================================
Counts the number of times @SearchString appears in @Input.
====================================================================================*/
ALTER FUNCTION dbo.com_CountString(@Input nVarChar(max), @SearchString nVarChar(1000))
RETURNS INT
BEGIN
DECLARE @Count INT, @Index INT, @InputLength INT, @SearchLength INT
DECLARE @SampleString INT
if @Input is null or @SearchString is null
return 0
SET @Count = 0
SET @Index = 1
SET @InputLength = LEN(@Input)
SET @SearchLength = LEN(@SearchString)
if @InputLength = 0 or @SearchLength = 0 or @SearchLength > @InputLength
return 0
WHILE @Index <= @InputLength - @SearchLength + 1
BEGIN
IF SUBSTRING(@Input, @Index, @SearchLength) = @SearchString
BEGIN
SET @Count = @Count + 1
SET @Index = @Index + @SearchLength
END
ELSE
SET @Index = @Index + 1
END
RETURN @Count
END
GO
And finally The function can be called:
SELECT dbo.com_CountString('This is a string', 'is')
SELECT dbo.com_CountString(MyTable.MyColumn, 'search string')
FROM MyTable
WHERE MyTable.MyKey = @Key
 Read more: |
|
Wednesday, 21 December 2011 01:13 |
Some times we need to detect the Browser Close to perform some operation before quiting from application. Here is a simple way.
Call this Method From Body Unload
function CheckBrowser()
{
// Check Browser Close [X] , Alt+F4 , File -> Close
if(window.event.clientX < 0 && window.event.clientY <0)
{
window.open("Operation.aspx",
"Operation",'left=12000,top=1200,width=10,height=1');
}
}
 Read more: |
|
|
|
|
|
|
Page 1 of 2 |