Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I Do Dynamic Query Construction in SQL Server SP
Message
De
11/10/2009 14:22:53
 
 
À
11/10/2009 14:15:46
Bill Drew
Independent Consultant
Chicago, Illinois, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
01428769
Message ID:
01428796
Vues:
57
>>>I have a VFP query screen that has several text boxes for entry of a the necessary values for a look up by last, first, dob, year of claim, and two case id numbers. In the "Do Query" click code, I create an SQL Select statement which combines the variables based on a useful logic (ie last and first and dob can claim year can be combined using AND logic -- if either of the claim IDs are filled in then the logic is a simple search just on the ID. if "is contained in" is checked the target word is preceded with the %. With SQLEXED, It is a great tool. But the company policy is to use stored procedures.
>>>
>>>So now I'm trying to implement it as a stored procedure. But I don't have enough experience to write this conditional logic in the stored procedure. If I pass all the query variables to the SP, can I evaluate which ones are non null and conditionally execute one Select statement or another?? If so, how does this procedural code look?
>>
>>You can use
>>
>>Isnull( @theParameter, replacementValueIfParameterIsNull)
>>
>>or:
>>
>>case when @theParameter is NULL then ... else @theParameter end
>>
>>T-SQL also supports conditionals like If ... then ... else
>>
>>Cetin
>
>Can you develop it a little more for me?
>
>For example
>
>Would I be about to conditionally call one SQL Select based on checking for Null parameters and call another SQL Select based on a different combination of Null and Non Null parameters??

There are examples:
http://sqlserver2000.databases.aspfaq.com/can-i-have-optional-parameters-to-my-stored-procedures.html
http://www.codeproject.com/KB/database/AdvancedSearchSP.aspx
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform