martes, 27 de septiembre de 2011

SQL Triggers

ALTER TRIGGER [STK35].[OrdFsstkCntUpd]

ON [STK35].[ORDFS]

AFTER UPDATE

AS

declare @OrdFsStkCnt as decimal(12,2), @OrdfsIdPrd AS CHAR(18), @MSAG AS CHAR(100)

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

select @OrdFsStkCnt=OrdFsStkCn, @OrdfsIdPrd =OrdfsIdPrd FROM inserted

SET @MSAG = 'UPD' + @OrdfsIdPrd + ' - ' + CAST(@OrdFsStkCnt AS CHAR)

INSERT INTO [dbo].[DebugTrigger]([sqltxt]) values (@MSAG )



END

viernes, 9 de septiembre de 2011

Genexus 9.0 - Visual Fox - Leer TXT

/*
&Archivo C(200)
&CntError n(10)
&Error  c(100)
&i n(2)
&IdArchi n(10)
&Linea c(350)
*/
&Archivo='navegacion'                       
        Call('gxSelFile',&Archivo ,'C:\scastriotta\KBS\GX90\UTL\DATA002','HTML' ,'Archivo' , , 0 )
DBase   if file([!&Archivo!])
DBase   [!&IdArchi!] = FOPEN([!&Archivo!],0)       
        If &IdArchi  < 0
            Msg('Error al leer el archivo.')
        Else               
DBase       Store fseek([!&IdArchi!]  ,0) to top           
DBase       Do WHILE .NOT. FEOF([!&IdArchi!])
DBase           [!&Linea!] = FGETS([!&IdArchi!])
                if
            (StrSearch(&Linea,'Update on')>0) .or.
                        (StrSearch(&Linea,'Delete from')>0) .or.  
                        (StrSearch(&Linea,'Insert into')>0)
                Do Case
                    Case StrSearch(&Linea,'Update on')>0
                    &NavAcc = 'Update on'
                    Case StrSearch(&Linea,'Delete from')>0
                    &NavAcc = 'Delete from'
                    Case StrSearch(&Linea,'Insert into')>0
                    &NavAcc = 'Insert into'
                EndCase
               
                DBase           [!&Linea!] = FGETS([!&IdArchi!])
                DBase           [!&Linea!] = FGETS([!&IdArchi!])
                    new
                        NavTable=   &Linea
                        NavAcc  =   &NavAcc
                    endnew
                endif
DBase       EndDo
DBase       fclose([!&IdArchi!] )
            If &CntError = 0
                Msg('El archivo se proceso correctamente')
            Else
                &Error = 'El archivo se proceso con errores(' + trim(str(&CntError )) + ')'
                msg(&Error)
            EndIf
        EndIf
Dbase   Else
            Msg('Error al tratar de leer el archivo.')       
Dbase   Endif

jueves, 8 de septiembre de 2011

SQL ver tablas lockeadas

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

You can use sp_lock (and sp_lock2), but in SQL Server 2005 onwards this is being deprecated in favour of querying sys.dm_tran_locks:
select   
    object_name(P.object_id) as TableName,  
    resource_type, resource_description 
from 
    sys.dm_tran_locks L 
    join sys.partitions P on L.resource_associated_entity_id = p.hobt_id 

sp_lock
When reading sp_lock information, use the OBJECT_NAME( ) function to get the name of a table from its ID number, for example:
SELECT object_name(16003073)
EDIT :
There is another proc provided by microsoft which reports objects without the ID translation : http://support.microsoft.com/kb/q255596/

http://dev.mysql.com/doc/refman/5.0/es/lock-tables.html`

select

object_name(P.object_id) as TableName,

resource_type, resource_description

from

sys.dm_tran_locks L

join sys.partitions P on L.resource_associated_entity_id = p.hobt_id

http://msdn.microsoft.com/es-es/library/ms186301.aspx

SELECT OBJECT_NAME(23007163)

sp_who2

sp_who   http://msdn.microsoft.com/es-es/library/ms174313.aspx

sp_lock