Monday, January 30, 2017

 

SQL Server - Modification du nom d'une colonne


https://msdn.microsoft.com/fr-fr/library/ms188351.aspx


L’exemple suivant renomme la TerritoryID colonne dans la SalesTerritory table TerrID.
USE AdventureWorks2012;  
GO  
EXEC sp_rename 'Sales.SalesTerritory.TerritoryID', 'TerrID', 'COLUMN';  
GO  

Tuesday, January 24, 2017


Copy de fichiers en commande DOS
 
Xcopy "chemin\nomfichier"  chemincible /y



Comparaison de 2 fichiers texte en commande DOS

 
 
FC chemin\fichier1.txt chemin\Fichier2.txt
 

How to display two digits after decimal point in SQL Server

 
select cast(your_float_column as decimal(10,2))
 


To display advanced properties scheduled tasks

 

https://technet.microsoft.com/en-us/library/bb490996.aspx

 

The following command requests a detailed display of the tasks on the local computer. It uses the /v parameter to request a detailed (verbose) display and the /fo LIST parameter to format the display as a list for easy reading. You can use this command to verify that a task you created has the intended recurrence pattern.

 
schtasks /query /fo LIST /v


Tuesday, January 10, 2017




Comparaison de 2 listes par SQL


Select Data
From
    (Select 'xxxxx' As Data union all
     ...
    Select 'xxxxx' As Data) as L1
Where L1.DI 
Not In
    (
        Select L2.Data
        From
           (Select 'xxxxx' As Data union all    
             ...
            Select 'xxxxx' As Data) as L2
     )
SQL server : fonctions perso traitement de chaines de caractères



USE [GDS]
GO

/****** Object:  UserDefinedFunction [dbo].[FNG_EXTRAITCHAINE]    Script Date: 12/23/2013 18:32:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO


CREATE FUNCTION [dbo].[FNG_EXTRAITCHAINE]
(
@psCh VarChar(1000),
@pnPos Integer,
@psSep VarChar(10)
) RETURNS varchar(255)
AS
-- Description:

BEGIN
            Declare @indice tinyint
            Declare @sRet VarChar(1000)  --  Pour la chaîne à retourner
            Declare @sChN VarChar(1000) --  Pour la chaîne extraite à la postion @pnPos par FNG_Substring_Index()
            Declare @sChNm1 VarChar(1000) --  Pour la chaîne extraite à la postion @pnPos-1 par FNG_Substring_Index()
            Declare @nTaille Integer --  @nTaille de la chaîne à extraire
            Declare @nTailleSep Integer --  @nTaille du séparateur
            Declare @nPosCh Integer --  Position de la chaîne à extraire

            Set @nTailleSep = LEN(@psSep)

            IF @pnPos = 1 
                                   Set @sRet                   = GDS.DBO.FNG_Substring_Index(@psCh, @psSep, @pnPos) 
            ELSE IF @pnPos > 1
                        Begin
                                   Set @sChNm1              = GDS.DBO.FNG_Substring_Index(@psCh, @psSep, @pnPos-1)
                                   Set @sChN                  = GDS.DBO.FNG_Substring_Index(@psCh, @psSep, @pnPos)
                                   Set @nTaille     = LEN(@sChN) - LEN(@sChNm1) - @nTailleSep
                                   Set @nPosCh               = LEN(@sChNm1) + @nTailleSep + 1
                                   Set @sRet                   = SUBSTRING(@psCh, @nPosCh, @nTaille)
                        End
            ELSE
                        Set @sRet = ''  --  Renvoie une chaîne vide pour les autres valeurs de Position

            RETURN @sRet

END
  
GO

==============================================================
  

USE [GDS]
GO

/****** Object:  UserDefinedFunction [dbo].[FNG_Substring_Index]    Script Date: 12/23/2013 18:34:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE FUNCTION [dbo].[FNG_Substring_Index]
(
@BaseString varchar(255),
@caracter varchar(255),
@pos tinyint
) RETURNS varchar(255)

AS

-- Description:
-- Equivalent de MySql Substring_index()

BEGIN

Declare @indice tinyint
Declare @pos2 tinyint
Declare @result varchar(255)

Declare @nNbSeparators integer

Set @nNbSeparators = GDS.[dbo].[Occurs](@BaseString, @caracter)

            -- Si le dernier paramètre est plus grand que le nombre de séparateurs 
            If @pos >= @nNbSeparators + 1
                        Return @BaseString
           
            -- Sinon
           
            Set @pos2= 1
            Set @indice = 0
           
            While @indice < @pos
            Begin
                        begin
                                   set @pos2 = CHARINDEX(@caracter,@BaseString,@pos2+1)
                                   set @indice = @indice +1
                        end

                        if @indice = @pos
                                   begin
                                               set @result=left(@BaseString,@pos2-1)
                                              
                                               break
                                   end
                        else
                                   continue
            End

            RETURN @result

END

GO