How to convert a SQL Server datetime column to a date in a remote view in Visual FoxPro 3.0

Article translations Article translations
Article ID: 137604 - View products that this article applies to.
This article was previously published under Q137604
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

To retrieve a datetime column value as a date (mm/dd/yy), a data type conversion must occur. For example, Microsoft SQL Server does not have a date data type; dates are always stored in a datetime format. This article describes how to convert the remote datetime data type to a date value by using the DbSetProp function. In Microsoft Visual FoxPro 3.0, you cannot do this by using the user interface when you create a remote view.

Note In Visual FoxPro 7.0 and later versions, you can change the data type of a field by using the Data type list in the View Field Properties dialog box of the View Designer.

MORE INFORMATION

Step-by-step procedure

  1. Create a new remote view by using the View Designer. Select the DataSource that opens the Pubs database supplied with SQL Server. Open the Sales table from the available tables in the Pubs database.

    NOTE: This process assumes that a connection has already been established to the Pubs database in SQL Server. The creation of remote connections is beyond the scope of this article. For more information on how to set up a connection, please see Chapter 7 of the "User's Guide" and Chapter 8 of the "Developer's Guide."
  2. Select the following columns: Store_id, Ord_num, Qty, Payterms, Title_id, and Date, or Select * to select all columns. The selected output should show:
       sales.stor_id, sales.ord_num, sales.qty, sales.payterms, sales.title_id,
       Sales.ord_date.
    						
    The SQL statement should be:
       SELECT Sales.stor_id, Sales.ord_num, Sales.qty, Sales.payterms,;
          Sales.title_id, Sales.ord_date;
          FROM dbo.sales Sales
    						
  3. Execute the view by clicking the exclamation mark (!). A result set containing a date column in the format "mon dd yyyy hh:miAM" (or PM), such as "Apr 15 1995 10:23AM" will display.
  4. Save the view as Sales_view.
  5. Create a form using the Form Designer, and include the "sales_view" in the data environment. Drag all the fields onto the form as text boxes. In the load event of the form, place the following code including the quotation marks:
       OPEN DATABASE mydata
       =DBSetProp("sales_view.ord_date","field","Datatype","D(8)")
    							
  6. Save and then run the form. Notice that the Ord_date field appears in the date format instead of the date time format.

REFERENCES

FoxPro Help: Client/Server Applications, Data Type Conversions, Changing Default Data Types when Downloading.

Language Reference, page 245, "Field Properties for Views."

Properties

Article ID: 137604 - Last Review: February 24, 2014 - Revision: 2.1
APPLIES TO
  • Microsoft Visual FoxPro 3.0 Standard Edition
Keywords: 
kbnosurvey kbarchive KB137604

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com