Advertisement
Guest User

Untitled

a guest
May 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.67 KB | None | 0 0
  1. USE [YOUR DB NAME]
  2. GO
  3. /****** Objet :  UserDefinedFunction [dbo].[GetPhaseParams]    Date de génération du script : 06/05/2010 12:24:43 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:      <Author,,Name>
  10. -- Create date: <Create Date, ,>
  11. -- Description: <Description, ,>
  12. -- =============================================
  13. CREATE FUNCTION [dbo].[GetPhaseParams]
  14. -- Add the parameters for the function here
  15. (
  16.     @RefExecution int
  17. )
  18. RETURNS nvarchar(1000)
  19. AS
  20. BEGIN
  21.     -- Declare the return variable here
  22.     declare @Result nvarchar(1000)
  23.     declare @Name nvarchar(1000)
  24.     declare @StringValue nvarchar(1000)
  25.     declare @FloatValue float
  26.     declare @BoolValue bit
  27.     declare CrsParams cursor fast_forward for
  28.         select [Name] as N , StringValue, BoolValue, FloatValue
  29.             from PhaseParameter
  30.             where Execution = @RefExecution
  31.             order by N
  32.  
  33.  
  34.     set @Result = ''
  35.     open CrsParams
  36.  
  37.     fetch next from CrsParams into @Name, @StringValue, @BoolValue,@FloatValue
  38.     while (@@FETCH_STATUS <> -1)
  39.     begin
  40.  
  41.         set @Result = @Result + ' ' + @Name + ':'
  42.  
  43.         if not @StringValue is null
  44.         begin
  45.             set @Result = @Result + @StringValue
  46.         end
  47.  
  48.         if not @FloatValue is null
  49.         begin
  50.             set @Result = @Result + cast (@FloatValue as nvarchar(17))
  51.         end
  52.  
  53.         if not @BoolValue is null
  54.         begin
  55.             if @BoolValue = 0
  56.                 set @Result = @Result + 'FALSE'
  57.             else
  58.                 set @Result = @Result + 'TRUE'
  59.        
  60.         end
  61.  
  62.         set @Result = @Result + ' '
  63.  
  64.         fetch next from CrsParams into @Name, @StringValue, @BoolValue,@FloatValue
  65.     end
  66.  
  67.     close CrsParams
  68.     deallocate CrsParams
  69.    
  70.     -- Return the result of the function
  71.     RETURN @Result
  72.  
  73. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement