Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Making freetext querys to MSSQL
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00544095
Message ID:
00544164
Vues:
14
>Hallo
>I have a question about making SQL-queries to a MS server.
>The user has a form with 30 fields, where he can put free text in, as he want, in 1, 2… or all fields.
>If I only had one field, I could have build the query like this, and it works perfect:
>***
>Par=”%some letters%”
>=SQLEXEC(MyConnection, "SELECT * FROM MyTable WHERE PATINDEX(?Par,Field1)<>0","Result")
>***
>BUT. How do I build the query if I want to search throw 2-30 different fields, with an AND between every “PATINDEX”?
>I don’t know from the beginning witch fields, or how many fields the user will put text in.
>In FoxPro I could build the WHERE-clause as a macro, but it is not a good solution in this case
> (I have no full-text index on the database, and I’m using VFP6).
>
>I hope you understand my question
>Thanks in advance
>/Kjell

I'm not sure I understand the question but, if you want the SQL equivalent of using a macro you might be able to use a stored procedure that accepts the criteria/field combination string as a parameter and construct the SQL on the fly and execute it via the sp_executesql stored procedure. Something like this:
Declare @SQLSt Varchar(500)
Set @SQLSt = 'Select * From Test Where ' + @parameter
Exec sp_executesql @SQLSt
Where @parameter is the input parameter on the stored procedure.
HTH
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform