Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Views
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00805855
Message ID:
00805950
Views:
24
Hi Bill

Hope this writeup from help helps.
Creating a Parameterized View

Use the CREATE SQL VIEW command with a "?" symbol and a parameter. 

OPEN DATABASE testdata
CREATE SQL VIEW customer_remote_view ;
   CONNECTION remote_01 ;
   AS SELECT * FROM customer ;
   WHERE customer.country = ?cCountry
You can supply a value for ?cCountry programmatically when you use the view. For example, you could type the following code:

cCountry = 'Sweden'
USE Testdata!customer_remote_view IN 0
BROWSE
Visual FoxPro displays the customer records for Swedish companies in the Browse window for Customer_remote_view.

Tip   If your parameter is an expression, enclose the parameter expression in parentheses. This allows the entire expression to be evaluated as part of the parameter.
Prompting for User Input of a Parameter Value
If your parameter is not a variable or expression, you might want to prompt the user to supply the parameter value by using a quoted string as your view parameter. When you create a view parameter using a quoted string after the "?" symbol, Visual FoxPro does not interpret the string as an expression. Rather, you are prompted to enter the value for the parameter at run time. For example, the following code creates a parameterized remote view that prompts the user to supply a value for the ?'my customer id' parameter:

OPEN DATABASE testdata
CREATE SQL VIEW customer_remote_view ;
   CONNECTION remote_01 ;
   AS SELECT * FROM customer ;
   WHERE customer.cust_id = ?'my customer id'
USE customer_remote_view
When you use the view in the previous example, the View Parameter dialog box is displayed.

After you enter a valid customer ID, Visual FoxPro retrieves the record that matches that ID. If you enter the value "ALFKI" in the previous example and then browse Customer_remote_view, you see the customer record displayed in the Browse window.

By using a quoted string as a view parameter, you ensure that Visual FoxPro will always prompt the user for the parameter value.
Aashish

>Is anyone aware of the capability of creating a parameterized SQL view that allow a common view to be executed with a passed variable that controls the scope of the records placed in the cursor...
>... or does anyone know of a workaround that would mimic that functionality ?
>
>The basic problem is to allow the script below to be executed with the entries in the cursor determined by the variable immediately following WHERE.
>
>TIA
>Bill
>
>
>CREATE SQL VIEW um REMOTE CONNECTION sqlWinMAGI AS ;
>SELECT Um.UM, Um.[DESC], Um.NODECIMALS;
> FROM dbo.UM Um WHERE &tcSqlWhere (could be 1=1, um = "EA", etc.)
>
>DBSetProp("um","View","SendUpdates",.T.)
>DBSetProp("um","View","BatchUpdateCount",1)
>DBSetProp("um","View","CompareMemo",.T.)
>DBSetProp("um","View","FetchAsNeeded",.F.)
>DBSetProp("um","View","FetchMemo",.T.)
>DBSetProp("um","View","FetchSize",-1)
>DBSetProp("um","View","MaxRecords",-1)
>DBSetProp("um","View","Prepared",.F.)
>DBSetProp("um","View","ShareConnection",.F.)
>DBSetProp("um","View","AllowSimultaneousFetch",.F.)
>DBSetProp("um","View","UpdateType",1)
>DBSetProp("um","View","UseMemoSize",255)
>DBSetProp("um","View","Tables","dbo.UM")
>DBSetProp("um","View","WhereType",1)
>
>DBSetProp("um"+".um","Field","DataType","C(4)")
>DBSetProp("um"+".um","Field","UpdateName","dbo.UM.UM")
>DBSetProp("um"+".um","Field","KeyField",.T.)
>DBSetProp("um"+".um","Field","Updatable",.T.)
>
>DBSetProp("um"+".desc","Field","DataType","C(30)")
>DBSetProp("um"+".desc","Field","UpdateName","dbo.UM.[DESC]")
>DBSetProp("um"+".desc","Field","KeyField",.F.)
>DBSetProp("um"+".desc","Field","Updatable",.T.)
>
>DBSetProp("um"+".nodecimals","Field","DataType","L")
>DBSetProp("um"+".nodecimals","Field","UpdateName","dbo.UM.NODECIMALS")
>DBSetProp("um"+".nodecimals","Field","KeyField",.F.)
>DBSetProp("um"+".nodecimals","Field","Updatable",.T.)
--
--
Aashish Sharma
Tele Nos: +1-201-490-5405
Mobile: +91-9821053938
E-Mail:
aashish@aashishsharma.com
write2aashish@gmail.com

You better believe in yourself... if you don't, who else will ?
TODAY is a gift, that's why it's called PRESENT
Previous
Reply
Map
View

Click here to load this message in the networking platform