USE [db_triana]
GO
/****** Object:  UserDefinedFunction [dbo].[FA_ID_MyCam]    Script Date: 2020/02/11 11:30:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

create FUNCTION [dbo].[FA_ID_MyCam](@id int)  
RETURNS nvarchar(500)  
AS  
BEGIN  
	 DECLARE @root_10000 nvarchar(500)
	 DECLARE @root_100 nvarchar(500)
     DECLARE @root_0 nvarchar(500)

	 set @root_10000=ltrim((@id / 10000) * 10000) + '-' +ltrim(((@id / 10000) * 10000) + 9999)
	 set @root_100=ltrim((@id / 100) * 100) + '-' +ltrim(((@id / 100) * 100) + 99)
	 set @root_0=@root_10000+'\'+@root_100+'\'+ltrim(@id) 

     RETURN @root_0 
END
/*
select [dbo].[FA_ID_MyCam](999000)
select [dbo].[FA_ID_MyCam](1)



 /*
DELPHI CODE

     root_10000 := Image_Path + '\' + IntToStr((p_id div 10000) * 10000) + '-' +
    IntToStr(((p_id div 10000) * 10000) + 9999);

  root_100 := root_10000 + '\' + IntToStr((p_id div 100) * 100) + '-' +
    IntToStr(((p_id div 100) * 100) + 99);

  root_0 := root_100 + '\' + IntToStr(p_id);

  if not DirectoryExists(root_10000) then
    CreateDir(root_10000);

  if not DirectoryExists(root_100) then
    CreateDir(root_100);

  if not DirectoryExists(root_0) then
    CreateDir(root_0);

   */


*/

