Foros del Web » Programando para Internet » ASP Clásico »

Consulta SQL con variables ASP como parámetro

Estas en el tema de Consulta SQL con variables ASP como parámetro en el foro de ASP Clásico en Foros del Web. Hola a todos!!! Necesito como siempre... Una mano(aunque no literalmente) Necesito hacer una consulta a la Db y lo que no recuerdo es cómo lograr ...
  #1 (permalink)  
Antiguo 25/10/2004, 09:08
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Consulta SQL con variables ASP como parámetro

Hola a todos!!!
Necesito como siempre... Una mano(aunque no literalmente)
Necesito hacer una consulta a la Db y lo que no recuerdo es cómo lograr que traiga todos los valores por defecto de una tabla, y luego pueda cambiarse asignando un valor diferente a la variable y entonces traiga otra cosa.
La cuestión mas claramente es asi:
Tabla Clientes
Nombre, Direccion, Telefono, Mail
necesito:
Por defecto: Todos los clientes listados, ordenados por nombre (lo se hacer)
Luego: Rellenando un campo con un string puede ocurrir:
Que sea un nombre completo
Que sea la primera letra o varias.
Lo que me complica es que en la consulta original debería traer todos los datos donde nombre sea igual a una variable PARAMETRO que inicialmente tiene que indicar un valor algo asi como a o true... y eso es lo que no recuerdo.... ¡¿Como lleno la variable, con que valor?! y ¡¿De que forma se lo asigno a la consulta?!
Se me había ocurrido poner dos variables y diferenciarlas con un XOR, ya que hay muchos clientes que comparten una palabra en el nombre, pero realmente no puedo encontrar la forma que funcione.
Puede alguien darme una mano?????
Se los agradezco con el corazón
Veronica
__________________
Why can't we not be sober?
www.partitorium.com.ar
  #2 (permalink)  
Antiguo 25/10/2004, 09:13
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Pues no te entiendo.......

¿Necesitas formar una consulta en ASP?
Rs.Open "Select * from tabla where nombre like '%" & campo & "%'"

sorry
  #3 (permalink)  
Antiguo 25/10/2004, 09:20
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Exactamente, pero hay un valor sql que indica cualquiera o todos, eso es lo que no recuerdo porque a "campo" tengo que asignarle un valor inicial que por defecto me devuelva todos los registros. Después, mientras el usuario interacrtúa especifica el nuevo valor de campo
__________________
Why can't we not be sober?
www.partitorium.com.ar
  #4 (permalink)  
Antiguo 25/10/2004, 09:46
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Vaya, pues de ese modificador no conocía (a no ser que sea ALL, SOME o ANY pero se ocupan con subconsultas).

A qué esta la lista de todo lo que WHERE acepta (lo tomé de la ayuda del SQLServer)

Cita:
Search Condition
Is a combination of one or more predicates using the logical operators AND, OR, and NOT.

Syntax
< search_condition > ::=
{ [ NOT ] < predicate > | ( < search_condition > ) }
[ { AND | OR } [ NOT ] { < predicate > | ( < search_condition > ) } ]
} [ ,...n ]

< predicate > ::=
{ expression { = | < > | ! = | > | > = | ! > | < | < = | ! < } expression
| string_expression [ NOT ] LIKE string_expression
[ ESCAPE 'escape_character' ]
| expression [ NOT ] BETWEEN expression AND expression
| expression IS [ NOT ] NULL
| CONTAINS
( { column | * } , '< contains_search_condition >' )
| FREETEXT ( { column | * } , 'freetext_string' )
| expression [ NOT ] IN ( subquery | expression [ ,...n ] )
| expression { = | < > | ! = | > | > = | ! > | < | < = | ! < }
{ ALL | SOME | ANY} ( subquery )
| EXISTS ( subquery )
}

Arguments
< search_condition >

Specifies the conditions for the rows returned in the result set for a SELECT statement, query expression, or subquery. For an UPDATE statement, specifies the rows to be updated. For a DELETE statement, specifies the rows to be deleted. There is no limit to the number of predicates that can be included in a Transact-SQL statement search condition.

NOT
Negates the Boolean expression specified by the predicate. For more information, see NOT.

AND
Combines two conditions and evaluates to TRUE when both of the conditions are TRUE. For more information, see AND.

OR
Combines two conditions and evaluates to TRUE when either condition is TRUE. For more information, see OR.
< predicate >

Is an expression that returns TRUE, FALSE, or UNKNOWN.

expression
Is a column name, a constant, a function, a variable, a scalar subquery, or any combination of column names, constants, and functions connected by an operator(s) or a subquery. The expression can also contain the CASE function.

=
Is the operator used to test the equality between two expressions.

<>
Is the operator used to test the condition of two expressions not being equal to each other.

!=
Is the operator used to test the condition of two expressions not being equal to each other.

>
Is the operator used to test the condition of one expression being greater than the other.

>=
Is the operator used to test the condition of one expression being greater than or equal to the other expression.

!>
Is the operator used to test the condition of one expression not being greater than the other expression.

<
Is the operator used to test the condition of one expression being less than the other.

<=
Is the operator used to test the condition of one expression being less than or equal to the other expression.

!<
Is the operator used to test the condition of one expression not being less than the other expression.

string_expression
Is a string of characters and wildcard characters.

[ NOT ] LIKE
Indicates that the subsequent character string is to be used with pattern matching. For more information, see LIKE.

ESCAPE 'escape_character'
Allows a wildcard character to be searched for in a character string instead of functioning as a wildcard. escape_character is the character that is placed in front of the wildcard character to denote this special use.

[ NOT ] BETWEEN
Specifies an inclusive range of values. Use AND to separate the beginning and ending values. For more information, see BETWEEN.

IS [ NOT ] NULL
Specifies a search for null values, or for values that are not null, depending on the keywords used. An expression with a bitwise or arithmetic operator evaluates to NULL if any of the operands is NULL.

CONTAINS
Searches columns containing character-based data for precise or "fuzzy" (less precise) matches to single words and phrases, the proximity of words within a certain distance of one another, and weighted matches. Can only be used with SELECT statements. For more information, see CONTAINS.

FREETEXT
Provides a simple form of natural language query by searching columns containing character-based data for values that match the meaning rather than the exact words in the predicate. Can only be used with SELECT statements. For more information, see FREETEXT.

[ NOT ] IN
Specifies the search for an expression, based on the expression's inclusion in or exclusion from a list. The search expression can be a constant or a column name, and the list can be a set of constants or, more commonly, a subquery. Enclose the list of values in parentheses. For more information, see IN.

subquery
Can be considered a restricted SELECT statement and is similar to <query_expresssion> in the SELECT statement. The ORDER BY clause, the COMPUTE clause, and the INTO keyword are not allowed. For more information, see SELECT.

ALL
Used with a comparison operator and a subquery. Returns TRUE for <predicate> if all values retrieved for the subquery satisfy the comparison operation, or FALSE if not all values satisfy the comparison or if the subquery returns no rows to the outer statement. For more information, see ALL.

{ SOME | ANY }
Used with a comparison operator and a subquery. Returns TRUE for <predicate> if any value retrieved for the subquery satisfies the comparison operation, or FALSE if no values in the subquery satisfy the comparison or if the subquery returns no rows to the outer statement. Otherwise, the expression is unknown. For more information, see SOME | ANY.

EXISTS
Used with a subquery to test for the existence of rows returned by the subquery. For more information, see EXISTS.
Remarks
The order of precedence for the logical operators is NOT (highest), followed by AND, followed by OR. The order of evaluation at the same precedence level is from left to right. Parentheses can be used to override this order in a search condition. For more information about how the logical operators operate on truth values, see AND, OR, and NOT.

Examples
A. Use WHERE with LIKE and ESCAPE syntax
This example assumes a description column exists in finances table. To search for the rows in which the description column contains the exact characters g_, use the ESCAPE option because _ is a wildcard character. Without specifying the ESCAPE option, the query would search for any description values containing the letter g followed by any single character other than the _ character.

SELECT *
FROM finances
WHERE description LIKE 'gs_' ESCAPE 's'
GO

B. Use WHERE and LIKE syntax with Unicode data
This example uses the WHERE clause to retrieve the contact name, telephone, and fax numbers for any companies containing the string snabbköp at the end of the company name.

USE Northwind
SELECT CompanyName, ContactName, Phone, Fax
FROM Customers
WHERE CompanyName LIKE N'%snabbköp'
ORDER BY CompanyName ASC, ContactName ASC
No se si alguno de los que ves aquí es el que ocupas.
  #5 (permalink)  
Antiguo 25/10/2004, 10:19
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
ok, Gracias de todos modos.
Voy a seguir buscando y en caso de encontrar la solución la estaré publicando en este tema.
Saluditos y mil gracias por tomarte el trabajo!!!
__________________
Why can't we not be sober?
www.partitorium.com.ar
  #6 (permalink)  
Antiguo 25/10/2004, 10:34
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Consulta SQL con Variables ASP

Ya lo Tengo!!!
Lo logré colocando en el valor de la variable como defecto "%%", entonces, inicialmente el like de consulta contiene el parámetro %% que es valido para todas las letras y simbolos que pudiera contener el nombre de campo!!!
Si alguien tiene una mejor solución... Acepto opiniones!
__________________
Why can't we not be sober?
www.partitorium.com.ar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:45.