Se utiliza cuando queremos saber si un valor en especifico de un campo se encuentra dentro de otra busqueda.
ejemplo tenemos un grupo de estudiantes y otro grupo de profesores
queremos buscar cuales estudiantes tambien son profesores, decimos
select nombre, apellido from estudiante where cedula IN (select nombre, apellido from profesores)
asi sabemos cuales estudiantes estan dentro de la consulta de profesores
Blog de algunos tips de programación que seran útiles a la hora de hacer un sistema y que pueden ser olvidados por los desarrolladores.
Bienvenidos
Recuerda que tus comentarios son importantes y recuerda agradecer si te fue útil algun artículo publicado aquí.
L1f3 15 a D@nc3 Flo0r
L1f3 15 a D@nc3 Flo0r
jueves, 26 de abril de 2007
Clausula Having
Se utiliza cuando queremos usar un campo calculado como filtro
ej.
queremos buscar las personas que esten repetidas mas de una vez en una lista
select count(codigo)
from tblPersonas
having count(codigo) > 1
ej.
queremos buscar las personas que esten repetidas mas de una vez en una lista
select count(codigo)
from tblPersonas
having count(codigo) > 1
sábado, 21 de abril de 2007
Crear una tabla en sql server
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Clases]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Clases]
GO
CREATE TABLE [dbo].[Clases] (
[ID_Clase] [int] IDENTITY (1, 1) NOT NULL ,
[id_Curso] [int] NULL ,
[ID_Departamento] [int] NOT NULL ,
[Fecha_Inicio] [datetime] NULL ,
[Fecha_Fin] [datetime] NULL ,
[Localidad] [varchar] (100)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]
GO
drop table [dbo].[Clases]
GO
CREATE TABLE [dbo].[Clases] (
[ID_Clase] [int] IDENTITY (1, 1) NOT NULL ,
[id_Curso] [int] NULL ,
[ID_Departamento] [int] NOT NULL ,
[Fecha_Inicio] [datetime] NULL ,
[Fecha_Fin] [datetime] NULL ,
[Localidad] [varchar] (100)
COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY]
GO
jueves, 12 de abril de 2007
UPDATE A UNA TABLA
CREATE PROCEDURE [update_Corredor_Metavolante_1]
(@gan_met_id_1 [int],
@gan_met_id_2 [int],
@corredor_id_3 [int],
@metavolante_id_4 [int])
AS UPDATE [dbCiclismo].[dbo].[Corredor_Metavolante]
SET [gan_met_id] = @gan_met_id_2,
[corredor_id] = @corredor_id_3,
[metavolante_id] = @metavolante_id_4
WHERE ( [gan_met_id] = @gan_met_id_1)
(@gan_met_id_1 [int],
@gan_met_id_2 [int],
@corredor_id_3 [int],
@metavolante_id_4 [int])
AS UPDATE [dbCiclismo].[dbo].[Corredor_Metavolante]
SET [gan_met_id] = @gan_met_id_2,
[corredor_id] = @corredor_id_3,
[metavolante_id] = @metavolante_id_4
WHERE ( [gan_met_id] = @gan_met_id_1)
viernes, 16 de febrero de 2007
The GridView fired event PageIndexChanging / Sorting which wasn't handled.
private string ConvertSortDirectionToSql(SortDirection sortDireciton)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection
}
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// Add here your method for DataBinding
BindGridControl();
gridView.PageIndex = e.NewPageIndex;
gridView.DataBind();
}
protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = gridView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
gridView.DataSource = dataView;
gridView.DataBind();
}
}
lunes, 12 de febrero de 2007
Guargar en BD los datos de un checkboxlist con un FOR
Esto es si queremos guardar en una BD todos los datos seleccionados en un CheckBoxList, utilizando un for.
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < CheckBoxList1.Items.Count - 1; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
objcmd = new SqlCommand("insert_Hospital_Copa", objconn);
objcmd.CommandType = CommandType.StoredProcedure;
objcmd.Parameters.AddWithValue("@hospital_id", GridView1.SelectedDataKey.Value);
objcmd.Parameters.AddWithValue("@copa", CheckBoxList1.Items[i].Text);
objconn.Open();
objcmd.ExecuteNonQuery();
lblmsg.Text = "Los datos han sido insertados";
objconn.Close();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < CheckBoxList1.Items.Count - 1; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
objcmd = new SqlCommand("insert_Hospital_Copa", objconn);
objcmd.CommandType = CommandType.StoredProcedure;
objcmd.Parameters.AddWithValue("@hospital_id", GridView1.SelectedDataKey.Value);
objcmd.Parameters.AddWithValue("@copa", CheckBoxList1.Items[i].Text);
objconn.Open();
objcmd.ExecuteNonQuery();
lblmsg.Text = "Los datos han sido insertados";
objconn.Close();
}
}
}
jueves, 1 de febrero de 2007
la dll de AJAX existe en dos directorios
The type 'xxxx' exists in both '...\v2.0.50727\Temporary\....xxx.dll' and '...\v2.0.50727\Temporary\...yyy.dll'
Location: BlogsMäx's blog
Posted by: m.unterauer
01.03.2006
This error occurs, if you have declared a class twice in your application (in a referenced assembly, somewhere in your app_code directory, or anywhere else in your app).In my case I had a prior compiled version (a dll) of the web app itself in the bin directory, which is not allowed any more. -> delete all compiled versions of all web applications (the app itself and referenced web apps) from the bin directory !!If you have to have the same classname multiple times within your application (e.g a class "DataAccess" within each module subfolder in the app_code directory, you could do the following:1) Give each class a different namespace (e.g. MODULENAME.DataAccess)2) Mark the classes as partial classes (!! this does not work if the partial classes are spread accross different subfolders of the app_code dir which are marked as codeSubDirectory in the web.config. The reason is, that in this case, each subfolder results in a different assembly and partial classes over multiple assemblies are not allowed. Also see my blog entry for creating multiple assemblies from the app_code directory !!)
Location: BlogsMäx's blog
Posted by: m.unterauer
01.03.2006
This error occurs, if you have declared a class twice in your application (in a referenced assembly, somewhere in your app_code directory, or anywhere else in your app).In my case I had a prior compiled version (a dll) of the web app itself in the bin directory, which is not allowed any more. -> delete all compiled versions of all web applications (the app itself and referenced web apps) from the bin directory !!If you have to have the same classname multiple times within your application (e.g a class "DataAccess" within each module subfolder in the app_code directory, you could do the following:1) Give each class a different namespace (e.g. MODULENAME.DataAccess)2) Mark the classes as partial classes (!! this does not work if the partial classes are spread accross different subfolders of the app_code dir which are marked as codeSubDirectory in the web.config. The reason is, that in this case, each subfolder results in a different assembly and partial classes over multiple assemblies are not allowed. Also see my blog entry for creating multiple assemblies from the app_code directory !!)
Suscribirse a:
Entradas (Atom)