Monday, February 25, 2019

Convert comma separated string values into integer values


Declare @ApiId varchar(max)
set @ApiId='10,20,30,40,50,60'
select * from [dbo].[fn_IntegerSplit](@ApiId,',')
-- in below select query Id is of Integer datatype
select value from [dbo].[fn_IntegerSplit](@ApiId,',')

Example:
value
10
20
30
40
50
60


GO
/****** Object:  UserDefinedFunction [dbo].[fn_IntegerSplit]    Script Date: 02/26/2019 12:27:37 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_IntegerSplit]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_IntegerSplit]
GO

/*
Declare @ApiId varchar(max)
set @ApiId='10,20,30,40,50,60'
select * from [dbo].[fn_IntegerSplit](@ApiId,',')
*/

Create FUNCTION [dbo].[fn_IntegerSplit]    
(    
 @List nvarchar(max),    
 @Separator nvarchar(5)    
)      
RETURNS @tmpTable table     
(    
      
 Id int identity(1,1),    
 Value nvarchar(100)    
)     
AS      
BEGIN    
    
While (Charindex(@Separator,@List)>0)    
Begin     
 Insert Into @tmpTable (value)    
 Select ltrim(rtrim(Substring(@List,1,Charindex(@Separator,@List)-1)))     
     
    Set @List = Substring(@List,Charindex(@Separator,@List)+len(@Separator),len(@List))    
End     
    Insert Into @tmpTable (Value)    
    Select ltrim(rtrim(@List))    
    delete from @tmpTable where Value = ''    
    Return    
END

GO

Server.MapPath

Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?

Server.MapPath specifies the relative or virtual path to map to a physical directory.

Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executed
Server.MapPath("..") returns the parent directory
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name
 (is not necessarily the same as the root of the application)

Server.MapPath(".")1 returns D:\WebApps\Site\DemoProducts
Server.MapPath("..") returns D:\WebApps\Site
Server.MapPath("~") returns D:\WebApps\Site
Server.MapPath("/") returns C:\Inetpub\wwwroot
Server.MapPath("/Site") returns D:\WebApps\Site


1) Server.MapPath(".") -- Returns the "Current Physical Directory" of the file (e.g. aspx) being executed.

Ex. Suppose  D:\WebApps\Site\DemoProducts

2) Server.MapPath("..") -- Returns the "Parent Directory"

Ex. D:\WebApps\Site

3) Server.MapPath("~") -- Returns the "Physical Path to the Root of the Application"

Ex. D:\WebApps\Site

4) Server.MapPath("/") -- Returns the physical path to the root of the Domain Name

Ex. C:\Inetpub\wwwroot