Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql dynamic
Message
 
 
To
17/10/2011 15:16:55
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01526661
Message ID:
01526666
Views:
53
>hi all, I need help with this, I want to do a consultation with several parameters in a stored procedure but these parameters do not always have values, but which depends on parameters chosen by the user in vfp I do by creating a variable with the possible selection conditions as follows
>cond= cond + "and x condition" and end of the WHERE I put the & cond. but not how to do something the same or similar in sql editor in stored procedure
>
>for example
>
>
>cond=''
>if !empty(thisform.txtfecha1.value)
>       mfecha=dtos(thisform.txtfecha.value)
>	condi=condi+[ and fecha>=']+mfecha1+[']
>        sql=[select * from tabla where x>0 &cond]
>endif
>
You will do the same in SQL Server by using dynamic SQL technique.

Here are several helpful blog posts explaining how to go about this problem:
Do you use ISNULL(...). Don't, it does not perform - short blog by Denis Gobo
Dynamic Search Conditions in T-SQL Version for SQL 2008 (SP1 CU5 and later) - long and comprehensive article by Erland Sommarskog 
Catch All Queries - short blog by Gail Shaw
Sunday T-SQL tip: How to select data with unknown parameter set Nice blog by Dmitri Korotkevitch

Option recompile

Option recompile discussion thread
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform