ado.net y sql server 2005 ado.net y sql server 2005 david salgado mvp c# [email protected]...
TRANSCRIPT
ADO.NET ySQL Server 2005 ADO.NET ySQL Server 2005
David SalgadoMVP C#[email protected]
David SalgadoMVP C#[email protected]
AgendaAgenda
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
AgendaAgenda
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
ADO.NETADO.NET
Clases, interfaces, estructuras y tipos que gestionan el acceso a los datos desde .NET (no sólo BBDD)
Enfocado al desarrollo en n-capas con XML como pilar
Los que vienen por defectoSystem.Data.OleDbSystem.Data.SqlClientSystem.Data.Odbc ( vs.net 2003 )System.Data.Oracle ( vs.net 2003 )Personalizados
Clases, interfaces, estructuras y tipos que gestionan el acceso a los datos desde .NET (no sólo BBDD)
Enfocado al desarrollo en n-capas con XML como pilar
Los que vienen por defectoSystem.Data.OleDbSystem.Data.SqlClientSystem.Data.Odbc ( vs.net 2003 )System.Data.Oracle ( vs.net 2003 )Personalizados
Componentes de ADO.NETComponentes de ADO.NET
Consumidores de datos
WinForm
WebForm
Otros
DataSet
Proveedores de datos
DataAdapter
Command
DataReaderConnection
ADO.NETADO.NET
Componentes de ADO.NETComponentes de ADO.NET
Proveedores de datosxxxConnectionxxxCommandxxxDataReaderxxxDataAdapter
Modo DesconectadoDataAdapter, DataSet
Proveedores de datosxxxConnectionxxxCommandxxxDataReaderxxxDataAdapter
Modo DesconectadoDataAdapter, DataSet
DataSetDataSet
Objeto estrella en ADO.NETRepresenta una caché de datos en memoriaContiene DataTablesLee y escribe datos y esquemas en XMLSerializablePuede ser tipado o no tipado:
El tipado se apoya en un esquema XML (.XSD) para generar la claseEl tipado tiene ventajas:
Conoce la estructura
Objeto estrella en ADO.NETRepresenta una caché de datos en memoriaContiene DataTablesLee y escribe datos y esquemas en XMLSerializablePuede ser tipado o no tipado:
El tipado se apoya en un esquema XML (.XSD) para generar la claseEl tipado tiene ventajas:
Conoce la estructura
DataSetDataSet
DataSetDataSet
DataTableDataTable
DataTableDataTable
DataRowDataRow
DataColumnDataColumn
RelationsRelations
ConstraintsConstraintsXML SchemaXML Schema
DataAdapterDataAdapter
DataAdapterDataAdapter
SelectCommandSelectCommand
InsertCommandInsertCommand
UpdateCommandUpdateCommand
DeleteCommandDeleteCommand
TableMappingsTableMappings
Base de datosBase de datos
DataSetDataSet
Modo ConectadoModo DesconectadoModo ConectadoModo Desconectado
ADO.NET¿Como escoger?ADO.NET¿Como escoger?
Que exista el modelo desconectado no quiere decir que lo usemos para todo
El acceso conectado es más rápido
Escenarios desconectadosNavegación en una aplicación WindowsEntornos móviles…
Cómo decidirArquitectura
http://msdn.microsoft.com/architecture“Patterns & Practices”
http://www.microsoft.com/resources/practicesBuilding Blocks
Que exista el modelo desconectado no quiere decir que lo usemos para todo
El acceso conectado es más rápido
Escenarios desconectadosNavegación en una aplicación WindowsEntornos móviles…
Cómo decidirArquitectura
http://msdn.microsoft.com/architecture“Patterns & Practices”
http://www.microsoft.com/resources/practicesBuilding Blocks
AgendaAgenda
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
Integración con XMLIntegración con XML
XML como almacén de información
Relación con el DataSet DataSet ds = new DataSet(); ds.ReadXml(“archivo.xml”); ds.Tables[0].Rows….. ds.WriteXml(“archivo.xml”);
APIs de trabajo con XMLDOM, SAX, XPathVendrán: XPath2, XQuery
XML como almacén de información
Relación con el DataSet DataSet ds = new DataSet(); ds.ReadXml(“archivo.xml”); ds.Tables[0].Rows….. ds.WriteXml(“archivo.xml”);
APIs de trabajo con XMLDOM, SAX, XPathVendrán: XPath2, XQuery
ADO.NET Integración con XMLADO.NET Integración con XML
Capa NegocioCapa Negocio
CapaCapaDatosDatos
Capa PresentaciónCapa Presentación
Web formsWeb forms
Negocio a NegocioNegocio a Negocio
DataSetDataSetDataSetDataSet
InternetInternetIntranetIntranet
DataAdapterDataAdapter
DataAdapterDataAdapterXmlXml
Aplicación.ExeAplicación.Exe
IEIE
DataSetDataSet
Windows formsWindows forms
XML como almacén de informaciónXML como almacén de información
AgendaAgenda
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
ADO.NETModo ConectadoModo DesconectadoIntegración con XML
Motores de BBDDSQL Server 2005
Curioso…Curioso…
¿Por qué no nos gustan las BBDD a los desarrolladores?
Ejercicios 3FNSQL = Simple Query LanguageNo optimizamos, no hacemos trucos,….
¿Por qué no nos gustan las BBDD a los desarrolladores?
Ejercicios 3FNSQL = Simple Query LanguageNo optimizamos, no hacemos trucos,….
Eso es sólo académicamente Eso es sólo académicamente
Motores de Base de DatosOrientados a archivoMotores de Base de DatosOrientados a archivo
La base de datos se encuentra en un archivo
ImplicacionesAcceso desde el clienteIneficiente en accesos simultáneosPara trabajar con aplicaciones distribuidas:
Replicarlos en los equiposDirectorios compartidos, FTPs…
Ejemplos:Clipper, MS Access (.mdb)
La base de datos se encuentra en un archivo
ImplicacionesAcceso desde el clienteIneficiente en accesos simultáneosPara trabajar con aplicaciones distribuidas:
Replicarlos en los equiposDirectorios compartidos, FTPs…
Ejemplos:Clipper, MS Access (.mdb)
Motores de Base de DatosOrientados a servidorMotores de Base de DatosOrientados a servidor
Ya no trabajamos contra un archivo, trabajamos contra un servicio
Preparado para accesos simultáneosCliente / Servidor
Ejemplos:SQL Server, Oracle, Informix, DB2, PostgreSQL…
Ya no trabajamos contra un archivo, trabajamos contra un servicio
Preparado para accesos simultáneosCliente / Servidor
Ejemplos:SQL Server, Oracle, Informix, DB2, PostgreSQL…
Motores de Base de DatosMitos, Leyendas y el sexo de los ángelesMotores de Base de DatosMitos, Leyendas y el sexo de los ángeles
Bases de Datos Orientadas a ObjetosMotores de persistencia SI
ObjectSpaces, Hibernate, …
¿Qué debemos hacer? ( básico )
Transact-SQL (T-SQL)Evitar select * from …;
Evitar búsquedas like ‘%tal’
Crear índices, pero no demasiadosSe obtienen buenas sugerencias desde el DTA (Database Tuning Advisor )
Definir el esquema de BD en 3FNClaves primarias, externas, etc.
Partir de un buen diseño y desnormalizar según necesidades del desarrollo
Bases de Datos Orientadas a ObjetosMotores de persistencia SI
ObjectSpaces, Hibernate, …
¿Qué debemos hacer? ( básico )
Transact-SQL (T-SQL)Evitar select * from …;
Evitar búsquedas like ‘%tal’
Crear índices, pero no demasiadosSe obtienen buenas sugerencias desde el DTA (Database Tuning Advisor )
Definir el esquema de BD en 3FNClaves primarias, externas, etc.
Partir de un buen diseño y desnormalizar según necesidades del desarrollo
Motores de Base de DatosSQL Server 2000Motores de Base de DatosSQL Server 2000
Notification ServicesNotification ServicesNotificaciones & AlertasNotificaciones & Alertas
Data Transformation ServicesData Transformation ServicesETLETL
SQL Server EngineSQL Server EngineRelational Database EngineRelational Database Engine
Reporting ServicesReporting ServicesInformes EmpresarialesInformes Empresariales
Herram
ien
tas d
e Gestió
nH
erramie
ntas
de G
estión
Her
ram
ien
tas
de
des
arro
llo
Her
ram
ien
tas
de
des
arro
llo
Replication ServicesReplication ServicesReplicación de DatosReplicación de Datos
Analysis ServicesAnalysis ServicesOLAP & Data MiningOLAP & Data Mining
Motores de Base de DatosMotores de Base de Datos
Integración del CLR en el motorSoporte HTTP (Servicios Web endpoints)Nuevo tipo de datos: XMLMejoras en T-SQLService BrokerNuevo modelo de seguridadMejoras en administración…
Integración del CLR en el motorSoporte HTTP (Servicios Web endpoints)Nuevo tipo de datos: XMLMejoras en T-SQLService BrokerNuevo modelo de seguridadMejoras en administración…
.NET FrameworkCommon Language Runtime IntegrationUser-defined AggregatesUser-defined Data TypesUser-defined FunctionsSQL Server .NET Data ProviderExtended Triggers
Data TypesManaged SQL TypesNew XML DatatypeVarchar (MAX) Varbinary (MAX)
SQL Server EngineNew Message Service BrokerHTTP Support (Native HTTP)Database Tuning Advisor Multiple Active Result Sets Persisted Computed ColumnsSnapshot Isolation Level Scale Up PartitioningVIA support NUMA support
Database Failure and RedundancyFail-over Clustering (up to 8 node)Enhanced Multi-instance SupportDatabase MirroringDatabase Snapshots
XMLXQUERY Support XML Data Manipulation Language FOR XML EnhancementsXML Schema (XSD) Support MSXML 6.0 (Native).Net XML Framework
Full-text SearchIndexing of XML Datatype
Database MaintenanceBackup and Restore EnhancementsChecksum Integrity ChecksDedicated Administrator ConnectionDynamic AWEFast RecoveryHighly-available UpgradeOnline Index OperationsOnline RestoreParallel DBCCParallel Index Operations
Management ToolsNew Management StudioMDX Query EditorVersion Control SupportXML/ASQLCMD Command Line Tool
Performance Tuning Profiler EnhancementsProfiling Analysis ServicesExportable Showplan Exportable Deadlock Traces
MDAC SNACMicrosoft Installer base setupSupport for Active Directory
DeploymentSQL Client .NET Data Provider
Server Cursor SupportAsynch
SecurityAll Permissions GrantableFine Grain Administration RightsSeparation of Users and SchemaData encryption primitives
ReplicationAuto-tuning Replication AgentsOracle PublicationImproved Blob Change Tracking Replication Monitor
OLAP and Data MiningAnalysis Management Objects Windows Integrated Backup and RestoreWeb Service/XML for AnalysisDTS and DM IntegrationNew Data Mining AlgorithmsAuto Packaging and Deployment
Data Transformation ServicesNew Architecture (DTR + DTP)Complex Control FlowsControl Flow DebuggingFor Each EnumerationsProperty MappingsFull Data Flow DesignerFull DTS Control Flow DesignerGraphical Presentation of Pkg ExecutionImmediate Mode and Project ModePackage (Advanced) Deployment ToolsCustom Tasks and Transformations
Reporting ServicesMultiple Output Formats Parameters (Static, Dynamic,
Hierarchical)Bulk Delivery of Personalized ContentSupport Multiple Data Sources STS (Web Parts, Doc Libraries)Visual Design ToolCharting, Sorting, Filtering, Drill-ThroughScheduling, CachingComplete Scripting EngineScale Out architectureOpen XML Report Definition
Notification Services & SQL Server CE
Programación en el motorProgramación en el motor
¿Qué se puede programar en el motor?Consultas y modificaciones sobre los datosDisparadores (triggers)Agrupar funcionalidad en procedimientos almacenadosFunciones definidas de usuario….
Es más, debe programarse el servidor XQuery – consulta sobre tipo de datos XMLT-SQL – extensión a SQLNET integrado en el motor - lenguajes
Cada cosa es para lo que es
¿Qué se puede programar en el motor?Consultas y modificaciones sobre los datosDisparadores (triggers)Agrupar funcionalidad en procedimientos almacenadosFunciones definidas de usuario….
Es más, debe programarse el servidor XQuery – consulta sobre tipo de datos XMLT-SQL – extensión a SQLNET integrado en el motor - lenguajes
Cada cosa es para lo que es
Programación en el MotorEjemplos T-SQLProgramación en el MotorEjemplos T-SQL
CREATE PROCEDURE CustOrdersOrders @CustomerID nchar(5)
ASSELECT OrderID,
OrderDate,RequiredDate,ShippedDate
FROM OrdersWHERE CustomerID = @CustomerIDORDER BY OrderID-- Exec CustOrdersOrders ‘ander’
CREATE PROCEDURE CustOrdersOrders @CustomerID nchar(5)
ASSELECT OrderID,
OrderDate,RequiredDate,ShippedDate
FROM OrdersWHERE CustomerID = @CustomerIDORDER BY OrderID-- Exec CustOrdersOrders ‘ander’
Programación en el MotorEjemplos T-SQL
Programación en el MotorEjemplos T-SQL
create proc dbo.dt_isundersourcecontrol @vchLoginName varchar(255) = '', @vchPassword varchar(255) = '', @iWhoToo int = 0 /* 0 => Just check project; 1 => get list of objs */as
set nocount ondeclare @iReturn intdeclare @iObjectId intselect @iObjectId = 0declare @VSSGUID varchar(100)select @VSSGUID = 'SQLVersionControl.VCS_SQL'declare @iReturnValue intselect @iReturnValue = 0declare @iStreamObjectId intselect @iStreamObjectId = 0declare @vchTempText varchar(255)
declare @iPropertyObjectId int select @iPropertyObjectId = (select objectid from dbo.dtproperties where property =
'VCSProjectID') declare @vchProjectName varchar(255) declare @vchSourceSafeINI varchar(255) declare @vchServerName varchar(255) declare @vchDatabaseName varchar(255) exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSProject',
@vchProjectName OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSourceSafeINI',
@vchSourceSafeINI OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLServer',
@vchServerName OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLDatabase',
@vchDatabaseName OUT if (@vchProjectName = '') set @vchProjectName
= null if (@vchSourceSafeINI = '') set @vchSourceSafeINI = null if (@vchServerName = '') set @vchServerName
= null if (@vchDatabaseName = '') set @vchDatabaseName = null if (@vchProjectName is null) or (@vchSourceSafeINI is null) or (@vchServerName is
null) or (@vchDatabaseName is null) begin RAISERROR('Not Under Source Control',16,-1) return end if @iWhoToo = 1 begin /* Get List of Procs in the project */ exec @iReturn = master.dbo.sp_OACreate @VSSGUID, @iObjectId OUT if @iReturn <> 0 GOTO E_OAError exec @iReturn = master.dbo.sp_OAMethod @iObjectId,
'GetListOfObjects',NULL,@vchProjectName,
@vchSourceSafeINI,@vchServerName,
@vchDatabaseName,@vchLoginName,
@vchPassword if @iReturn <> 0 GOTO E_OAError exec @iReturn = master.dbo.sp_OAGetProperty @iObjectId, 'GetStreamObject',
@iStreamObjectId OUT if @iReturn <> 0 GOTO E_OAError create table #ObjectList (id int identity, vchObjectlist varchar(255)) select @vchTempText = 'STUB' while @vchTempText is not null begin exec @iReturn = master.dbo.sp_OAMethod @iStreamObjectId, 'GetStream',
@iReturnValue OUT, @vchTempText OUT if @iReturn <> 0 GOTO E_OAError if (@vchTempText = '') set @vchTempText = null if (@vchTempText is not null) insert into #ObjectList (vchObjectlist ) select
@vchTempText end select vchObjectlist from #ObjectList order by id endCleanUp: returnE_OAError: exec dbo.dt_displayoaerror @iObjectId, @iReturn goto CleanUp
create proc dbo.dt_isundersourcecontrol @vchLoginName varchar(255) = '', @vchPassword varchar(255) = '', @iWhoToo int = 0 /* 0 => Just check project; 1 => get list of objs */as
set nocount ondeclare @iReturn intdeclare @iObjectId intselect @iObjectId = 0declare @VSSGUID varchar(100)select @VSSGUID = 'SQLVersionControl.VCS_SQL'declare @iReturnValue intselect @iReturnValue = 0declare @iStreamObjectId intselect @iStreamObjectId = 0declare @vchTempText varchar(255)
declare @iPropertyObjectId int select @iPropertyObjectId = (select objectid from dbo.dtproperties where property =
'VCSProjectID') declare @vchProjectName varchar(255) declare @vchSourceSafeINI varchar(255) declare @vchServerName varchar(255) declare @vchDatabaseName varchar(255) exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSProject',
@vchProjectName OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSourceSafeINI',
@vchSourceSafeINI OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLServer',
@vchServerName OUT exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLDatabase',
@vchDatabaseName OUT if (@vchProjectName = '') set @vchProjectName
= null if (@vchSourceSafeINI = '') set @vchSourceSafeINI = null if (@vchServerName = '') set @vchServerName
= null if (@vchDatabaseName = '') set @vchDatabaseName = null if (@vchProjectName is null) or (@vchSourceSafeINI is null) or (@vchServerName is
null) or (@vchDatabaseName is null) begin RAISERROR('Not Under Source Control',16,-1) return end if @iWhoToo = 1 begin /* Get List of Procs in the project */ exec @iReturn = master.dbo.sp_OACreate @VSSGUID, @iObjectId OUT if @iReturn <> 0 GOTO E_OAError exec @iReturn = master.dbo.sp_OAMethod @iObjectId,
'GetListOfObjects',NULL,@vchProjectName,
@vchSourceSafeINI,@vchServerName,
@vchDatabaseName,@vchLoginName,
@vchPassword if @iReturn <> 0 GOTO E_OAError exec @iReturn = master.dbo.sp_OAGetProperty @iObjectId, 'GetStreamObject',
@iStreamObjectId OUT if @iReturn <> 0 GOTO E_OAError create table #ObjectList (id int identity, vchObjectlist varchar(255)) select @vchTempText = 'STUB' while @vchTempText is not null begin exec @iReturn = master.dbo.sp_OAMethod @iStreamObjectId, 'GetStream',
@iReturnValue OUT, @vchTempText OUT if @iReturn <> 0 GOTO E_OAError if (@vchTempText = '') set @vchTempText = null if (@vchTempText is not null) insert into #ObjectList (vchObjectlist ) select
@vchTempText end select vchObjectlist from #ObjectList order by id endCleanUp: returnE_OAError: exec dbo.dt_displayoaerror @iObjectId, @iReturn goto CleanUp
select @vchTempText = 'STUB'select @vchTempText = 'STUB' while @vchTempText is not nullwhile @vchTempText is not null beginbegin exec @iReturn = ster.dbo.sp_OAMethod exec @iReturn = ster.dbo.sp_OAMethod
@iStreamObjectId, 'GetStream', @iStreamObjectId, 'GetStream', @iReturnValue OUT, @vchTempText @iReturnValue OUT, @vchTempText
OUTOUT if @iReturn <> 0 GOTO E_OAErrorif @iReturn <> 0 GOTO E_OAError if (@vchTempText = '') if (@vchTempText = '')
set @vchTempText = nullset @vchTempText = null if (@vchTempText is not null) if (@vchTempText is not null) insert into #ObjectList insert into #ObjectList
(vchObjectlist ) (vchObjectlist ) select @vchTempTextselect @vchTempText endend
Prodecimiento almacenado desde ADO.NETProdecimiento almacenado desde ADO.NET
Programación en el Motor.NETProgramación en el Motor.NET
Se desarrolla con Visual Studio 2005
Depuración, puntos de interrupción :O
Los ensamblados se almacenan en SQL Server 2005Permite extender el sistema
Funciones escalares
Tipos
Triggers
Agregados
ProcedimientosAcceso a datos
Se desarrolla con Visual Studio 2005
Depuración, puntos de interrupción :O
Los ensamblados se almacenan en SQL Server 2005Permite extender el sistema
Funciones escalares
Tipos
Triggers
Agregados
ProcedimientosAcceso a datos
SQL EngineSQL Engine
WindowsWindows
SQL OSSQL OS
CLRCLR
HostingHostingLayerLayer
Programación en el MotorProgramación en el Motor
¿Cuándo .NET?Procesos complejos
Impuestos, descuentos, cálculos matemáticos
Acceso a recursos externosFicheros, sockets, Servicios web, …
Proceso de imágenesAplicaciones científicasGestión de cadenasDepuraciónLocalización
¿Cuándo .NET?Procesos complejos
Impuestos, descuentos, cálculos matemáticos
Acceso a recursos externosFicheros, sockets, Servicios web, …
Proceso de imágenesAplicaciones científicasGestión de cadenasDepuraciónLocalización
Tecnología Utilizada SQL Server 2005Tecnología Utilizada SQL Server 2005
A la vieja usanza…. A la vieja usanza…. declare @str varchar(200)declare @str varchar(200)select @Str = 'Microsoft Corporation|SQL Server|2003|select @Str = 'Microsoft Corporation|SQL Server|2003|SQL-CLR|2002-08-20|11:32:00|Document|3.b.3'SQL-CLR|2002-08-20|11:32:00|Document|3.b.3'SELECTSELECTsubstring(@Str + '|', 0 + 1, substring(@Str + '|', 0 + 1, charindex('|', @Str + '|', 0 + 1) - 0 - 1 ),charindex('|', @Str + '|', 0 + 1) - 0 - 1 ),substring(@Str + '|', charindex('|', @Str + '|') + 1, substring(@Str + '|', charindex('|', @Str + '|') + 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) - charindex('|', @Str + '|') + 1) - charindex('|', @Str + '|') - 1 ),charindex('|', @Str + '|') - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1,charindex('|', @Str + '|') + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) - 1 ),charindex('|', @Str + '|') + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1, charindex('|', @Str + '|') + 1) + 1) + 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1,charindex('|', @Str + '|') + 1) + 1) + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1,charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1, 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1) - charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|', '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - 1 ),1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1,1) + 1, charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|', charindex('|', @Str + charindex('|', @Str + '|', charindex('|', @Str + '|','|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1) - 1) + 1) - charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1 ) 1) - 1 )
declare @str varchar(200)declare @str varchar(200)select @Str = 'Microsoft Corporation|SQL Server|2003|SQL-CLR|2002-select @Str = 'Microsoft Corporation|SQL Server|2003|SQL-CLR|2002-08-20|11:32:00|Document|3.b.3'08-20|11:32:00|Document|3.b.3'SELECTSELECTsubstring(@Str + '|', 0 + 1, substring(@Str + '|', 0 + 1, charindex('|', @Str + '|', 0 + 1) - 0 - 1 ),charindex('|', @Str + '|', 0 + 1) - 0 - 1 ),substring(@Str + '|', charindex('|', @Str + '|') + 1, substring(@Str + '|', charindex('|', @Str + '|') + 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) - charindex('|', @Str + '|') + 1) - charindex('|', @Str + '|') - 1 ),charindex('|', @Str + '|') - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1,charindex('|', @Str + '|') + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) - 1 ),charindex('|', @Str + '|') + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1, charindex('|', @Str + '|') + 1) + 1) + 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1,charindex('|', @Str + '|') + 1) + 1) + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1,charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) -charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1, charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1, charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - 1 ),charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) - 1 ),substring(@Str + '|', charindex('|', @Str + '|', substring(@Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1,charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1, charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) + 1) - charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|',charindex('|', @Str + '|', charindex('|', @Str + '|', charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1 ) charindex('|', @Str + '|') + 1) + 1) + 1) + 1) + 1) + 1) - 1 )
Tecnología Utilizada SQL Server 2005Tecnología Utilizada SQL Server 2005
public static void SplitString()public static void SplitString(){{ string s;string s; s = “Microsoft s = “Microsoft Corporation|SQLServer|2003|SQL-CLR|2004-08-Corporation|SQLServer|2003|SQL-CLR|2004-08-20|22:00:00|Document|3.b.3“;20|22:00:00|Document|3.b.3“; string[] miArray = string[] miArray = s.Split(s, "|")s.Split(s, "|");;}}
Ahora tenemos la posibilidad de…
RecursosRecursos
www.siquelnet.com [1]
www.portalsql.com [2]
www.helpdna.net
www.solidqualitylearning.com
www.sqljunkies.com
News de Microsoft Grupo de usuarios de SqlServer
[1] y [2]
www.siquelnet.com [1]
www.portalsql.com [2]
www.helpdna.net
www.solidqualitylearning.com
www.sqljunkies.com
News de Microsoft Grupo de usuarios de SqlServer
[1] y [2]
¿ Preguntas ?¿ Preguntas ?Gracias Gracias
© 2004, 2005 Microsoft Corporation. Todos los derechos reservados.© 2004, 2005 Microsoft Corporation. Todos los derechos reservados.Esta presentación tiene propósito informativo únicamente. Microsoft no ofrece ninguna garantía , expresa o implítica, en este documento.Esta presentación tiene propósito informativo únicamente. Microsoft no ofrece ninguna garantía , expresa o implítica, en este documento.