functions.sql 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. -- ============================================================================
  2. -- Copyright (C) 2007 Regis Houssin <regis@dolibarr.fr>
  3. -- Copyright (C) 2007 Simon Desee <simon@dedisoft.com>
  4. --
  5. -- This program is free software; you can redistribute it and/or modify
  6. -- it under the terms of the GNU General Public License as published by
  7. -- the Free Software Foundation; either version 3 of the License, or
  8. -- (at your option) any later version.
  9. --
  10. -- This program is distributed in the hope that it will be useful,
  11. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. -- GNU General Public License for more details.
  14. --
  15. -- You should have received a copy of the GNU General Public License
  16. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. -- or see http://www.gnu.org/
  18. --
  19. -- ============================================================================
  20. SET QUOTED_IDENTIFIER ON
  21. GO
  22. SET ANSI_NULLS ON
  23. GO
  24. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'unix_timestamp') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  25. BEGIN
  26. execute dbo.sp_executesql @statement = N'
  27. CREATE FUNCTION unix_timestamp
  28. (
  29. @Date datetime
  30. )
  31. RETURNS varchar (19)
  32. AS
  33. BEGIN
  34. DECLARE @Result int
  35. --SET @Result = NULL
  36. --IF @Date IS NOT NULL SET @Result = DATEDIFF(s, '19700101', @Date)
  37. RETURN convert(varchar(19), @Date, 120);
  38. END
  39. END
  40. GO
  41. SET QUOTED_IDENTIFIER ON
  42. GO
  43. SET ANSI_NULLS ON
  44. GO
  45. IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'from_unixtime') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  46. BEGIN
  47. execute dbo.sp_executesql @statement = N'
  48. CREATE FUNCTION from_unixtime
  49. (
  50. @Epoch int
  51. )
  52. RETURNS datetime
  53. AS
  54. BEGIN
  55. RETURN DATEADD(s, @Epoch, ''19700101'');
  56. END
  57. END
  58. GO
  59. SET QUOTED_IDENTIFIER ON
  60. GO
  61. SET ANSI_NULLS ON
  62. GO
  63. IF NOT EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'llx_bordereau_cheque_number'))
  64. EXEC dbo.sp_executesql @statement = N'
  65. -- FILLZERO du number
  66. CREATE TRIGGER llx_bordereau_cheque_number
  67. ON llx_bordereau_cheque
  68. AFTER INSERT, UPDATE
  69. AS
  70. BEGIN
  71. -- SET NOCOUNT ON added to prevent extra result sets from
  72. -- interfering with SELECT statements.
  73. SET NOCOUNT ON;
  74. DECLARE @numero as varchar(5)
  75. SELECT @numero = right(''00000'' + cast(number AS varchar(5)),5)
  76. from llx_bordereau_cheque
  77. where rowid in (select rowid from inserted)
  78. update llx_bordereau_cheque set number = @numero
  79. where rowid in (select rowid from inserted)
  80. END
  81. GO