jueves, 3 de julio de 2008

Concurso de tapas decalles. V edición.2008

Apunto los bares que han sido galardonados en la V edición:

Jurado:
- 1. Duque
- 2. DiVino y Restaurante Bar Judería

Público:
- 1. Fogón Sefardí
- 2. Casares

Personal(clasificación de las probadas)
1. Jose(Muy bien, rico y muy grande)Aparte, el champiñon lo tienen estupendo.
2. Hotel san miguel(bien, rico algo escaso)
3. Catedral(bien, rico algo escaso)
4. As de picas.(mal, simplemente no me gusto)

miércoles, 24 de octubre de 2007

Sobre queries de duplicados

1. Query para encontrar duplicados


SELECT
id, COUNT(1)
FROM table
GROUP BY id
HAVING ( COUNT(id) > 1 )

2. Select quedandonos el más nuevo de los repetidos
/**/
create table tmp
(
intid int,
intindex int
)

insert into tmp values (1,1)
insert into tmp values (2,2)
insert into tmp values (2,3)

select
AA.*
from
tmp AA

select
AA.*
from
tmp AA,
(select intid,max(intindex) as intindex from tmp group by intid ) BB
where
aa.intid=bb.intid
and aa.intindex =bb.intindex

martes, 23 de octubre de 2007

Template de SP en T-SQL

CREATE PROCEDURE template..............
(
@strKey varchar(20),
@strerror varchar(255) OUTPUT
)
as
/*
---------------------------------------------------------------------------------------
Procedure : template..............
DateTime : ?
Author : ?
Purpose : ?
---------------------------------------------------------------------------------------
Description : ?
Change Log :
Date :
Details : Return a parameter or list of parameters
Eaxmple :
--1. CALL
DECLARE @STRERROR AS VARCHAR(255)
SET @STRERROR ='INIT'
--EXEC template.............. 'PercentBrand',@STRERROR OUTPUT
EXEC template.............. 'ProductType',@STRERROR OUTPUT
SELECT @STRERROR

--2. EXAMPLE TO OBTAIN THE TYPE OF COLUMN
CREATE TABLE #tabletmp(colA sql_variant)
insert #tabletmp exec template.............. 'PercentBrand',''
--insert #tabletmp exec template.............. 'ProductType',''
SELECT SQL_VARIANT_PROPERTY(colA,'BaseType') from #tabletmp
SELECT SQL_VARIANT_PROPERTY(colA,'Precision') from #tabletmp
SELECT SQL_VARIANT_PROPERTY(colA,'Scale') from #tabletmp
SELECT SQL_VARIANT_PROPERTY(colA,'MaxLength') from #tabletmp
SELECT SQL_VARIANT_PROPERTY(colA,'Collation') from #tabletmp
SELECT SQL_VARIANT_PROPERTY(colA,'TotalBytes') from #tabletmp

drop TABLE #tabletmp
---------------------------------------------------------------------------------------
*/
-- This is to subquerys fix(Crystal reports, several sps )
--
SET NOCOUNT ON
---------------
-- DECLARATION
---------------
DECLARE @strSQL AS nvarchar(4000)
DECLARE @interror AS int
DECLARE @introwcount AS int
--
DECLARE @strtype as varchar(20)
DECLARE @intPrecision as int
DECLARE @intScale as int
---------------
SET @strerror ='True'

-- 1. Obtain Data type

SELECT
@strtype =strtype ,@intPrecision=intPrecision,@intScale=intScale
FROM
template...table with (nolock)
WHERE
strkey=@strKey

SELECT @interror=@@error,@introwcount=@@rowcount

IF @interror<>0
BEGIN
SET @strerror = 'Error:Selecting Parameter'
RETURN
END


-- 2. Create SQL STRING:
--
SET @strSQL =
CASE
WHEN lower(@strtype) in ('int','varchar','bigint','smallint','tinyint','bit','money','smallmoney','float','real')
THEN 'Select cast(strvalue as '+ @strtype +') as objvalue from template.............. where strkey=''' +@strKey +''''
WHEN lower(@strtype)='decimal'
THEN 'Select cast(strvalue as '+ @strtype +'('+cast(@intPrecision as varchar)+','+cast(@intScale as varchar)+')) as objvalue from template.............. where strkey=''' +@strKey +''''
ELSE
'Error'
END
IF @strSQL='Error'
BEGIN
SET @strerror = 'Error: the parameter type['+@strtype+'] is not supported yet'
RETURN
END

/* EXAMPLE OF RESULT
SELECT
strvalue,cast(5 as int) as objvalue,strtype
FROM
template.............. with (nolock)
WHERE
strkey=@strKey*/

EXECUTE sp_executesql @strSQL

SELECT @interror=@@error,@introwcount=@@rowcount

IF @interror<>0
BEGIN
SET @strerror = 'Error:Selecting Parameter'
RETURN
END



GO

jueves, 18 de octubre de 2007

Sobre @@, funciones de meta data y esas cosas

Recordar alguna de las variables que nos pueden ser de utilidad, como por ejemplo la version de windows , el lenguaje , el id....... :
select @@version
--exec master..xp_msver
select @@SERVERNAME
select @@LANGUAGE
select @@SERVICENAME
select @@LOCK_TIMEOUT
select @@SPID
--SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name'
select @@MAX_CONNECTIONS
select @@TEXTSIZE
select @@MAX_PRECISION

Otra info util es obtener el tipo de una columna
CREATE TABLE tableA(colA sql_variant, colB int)
INSERT INTO tableA values ( cast (46279.1 as decimal(8,2)), 1689)
SELECT SQL_VARIANT_PROPERTY(colA,'BaseType'),
SQL_VARIANT_PROPERTY(colA,'Precision'),
SQL_VARIANT_PROPERTY(colA,'Scale')
FROM tableA
WHERE colB = 1689



COL_LENGTH
COL_NAME
COLUMNPROPERTY
INDEX_COL
DATABASEPROPERTYEX
INDEXKEY_PROPERTY
DB_ID
INDEXPROPERTY
DB_NAME
OBJECT_ID
FILE_ID
OBJECT_NAME
FILE_NAME
OBJECTPROPERTY
FILEGROUP_ID
@@PROCID
FILEGROUP_NAME
SQL_VARIANT_PROPERTY
FILEGROUPPROPERTY
TYPEPROPERTY
FILEPROPERTY

jueves, 11 de octubre de 2007

Insertar el resultado de un sp y algo más

Para tener a mano el código que inserta el resultado de un sp, busque en internet y encontre algún plus:
1. lo básico
set nocount on
create table #sp_who (
spid smallint,
ecid smallint,
status nchar(30),
loginame nchar(128),
hostname nchar(128),
blk char(5),
dbname nchar(128),
cmd nchar(16))
insert into #sp_who execute sp_who
select * from #sp_who
drop table #sp_who

2. El contenido de un fichero a tabla

create table #errorlog(line varchar(2000))
insert into #errorlog
execute xp_cmdshell 'type "C:\Program Files\Microsoft SQL Server\MSSQL\LOG\ERRORLOG" '
select line from #errorlog
drop table #errorlog

3. Insertar multiples lineas en una tabla
create table #errorlog(line varchar(2000))
execute master.dbo.xp_cmdshell 'osql -SYourSQLMachine
-E -Q"execute sp_spaceused" -o"c:\temp\sp_out.txt" -s"" '
insert into #errorlog
execute master.dbo.xp_cmdshell 'type "c:\temp\sp_out.txt" '
select line from #errorlog
drop table #errorlog

4. La salida de un ejecutable a tabla(mucho ojito en 2000 o anteriores)
create table #ipconfig(line varchar(2000))
insert into #ipconfig
execute xp_cmdshell 'ipconfig.exe'
select line from #ipconfig
drop table #ipconfig




Referencia
http://www.databasejournal.com/features/mssql/article.php/3386661
Más articulos de este tio (Echales un ojo)

martes, 9 de octubre de 2007

SQL SERVER las funciones password(ejemplo de uso)

Ejemplos de uso:
El resultado es almacenado como VarBinary (256)
select pwdencrypt('foo')
select pwdcompare('foo',0x0100981F6344718E0C1859FCF0676BEC1760D6147A38C2471E0CAC8E35E976ADA451FFBE9ECA7172DD0AECD6D12F)
select pwdcompare('fo2',0x0100981F6344718E0C1859FCF0676BEC1760D6147A38C2471E0CAC8E35E976ADA451FFBE9ECA7172DD0AECD6D12F)

Estas funciones trabajan sobre:


referencias:
-->explica como romperla y con algo de tetalle que es lo que hay.
http://www.ngssoftware.com/papers/cracking-sql-passwords.pdf

Sobre el IPC y la nómina

Cuando en la empresa te dicen que no tiene que subirte el sueldo parece que tienen razón, parece que están obligados a hacerlo pero sobre el salario base con lo cual no tiene porque aumentarte la nomina ni un €.

http://foros.emagister.com/tema-subida_ipc-13709-281831.htm

Links relacionados:
calcular el ipc: http://www.ine.es/cgi-bin/certi
Convenios: http://fes.ugt.org/mediosdecomunicacion/convenios/index.htm
Convenios publicidad: http://fes.ugt.org/mediosdecomunicacion/convenios/index.htm#PUBLI