Tengo la siguiente función para construir una Select en función de diferentes parámetros que pueden seleccionarse en un formulario:
Código:
Si los parámetros enviados hacen que SelectCommand sea demasiado largo me da problemas ya que no recoge todos los caracteres que debiera. Function montarSelect(ByVal tipologias As String, ByVal subAct As Integer, _
ByVal soloActivos As Boolean, ByVal grupoClientes As Integer) As String
Dim clausulaWhere As String
Dim selectCommand As String
clausulaWhere = "where "
' tipologias: String con los tipos seleccionado "'E', 'F', 'I', 'A', ..."
' subAct: Subactividad
' soloActivos: Proyectos con periodo dentro del año seleccionado
If tipologias <> "" Then
clausulaWhere = clausulaWhere _
& "substring(id_proyecto, 1, 1) in(" & tipologias & ") "
If subAct <> 0 Then
' Si no ha elejido todas las Subactividades de este tipo de Actividad
If Not CInt(subAct) = 0 Then
clausulaWhere = clausulaWhere _
& " and subactividad = " & subAct
End If
End If
If soloActivos Then
clausulaWhere = clausulaWhere _
& " and (year(fecha_inicio) >= year(GetDate()) " _
& " or year(fecha_final) >= year(GetDate())) "
End If
If grupoClientes <> "0" Then
clausulaWhere = clausulaWhere _
& " and grupoCliente"
End If
ElseIf subAct <> 0 Then
' Si no ha elejido todas las Subactividades de este tipo de Actividad
If Not CInt(subAct) = 0 Then
clausulaWhere = clausulaWhere _
& " and subactividad = " & subAct
End If
If soloActivos Then
clausulaWhere = clausulaWhere _
& " and (year(fecha_inicio) >= year(GetDate()) " _
& " or year(fecha_final) >= year(GetDate())) "
End If
ElseIf soloaActivos Then
clausulaWhere = clausulaWhere _
& "subactividad = " & subAct
End If
clausulaWhere = clausulaWhere & " order by id_proyecto "
selectCommand = "select id_proyecto, nombre, descripcion, cliente, fecha_inicio, fecha_final " _
& "from proyectos " _
& clausulaWhere _
montarSelect = selectCommand
End Function
Por ejemplo haciendo la siguiente llamada
Código:
la variable selectCommand contiene: montarSelect("'I'", 1, True, 0)
"select id_proyecto, nombre, descripcion, cliente, fecha_inicio, fecha_final from proyectos where substring(id_proyecto, 1, 1) in('I') and subactividad = 1 and (year(fecha_inicio) >= year(GetDate()) or year(fecha_final) >= year(GetDate())) order byi"
Si recibe otros parámetros que crean una select más corta, no tengo ningún problema pero.. no parece que el problema sea la longitud.
Alguien puede ayudarme?
Muchas gracias

