Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert blank date field to null
Message
De
05/10/2010 10:52:16
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
04/10/2010 09:33:52
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01483799
Message ID:
01483981
Vues:
47
>We have a foxpro dbf file that contains a date field 'date1'. We need to import this dbf to SQL Server using the OLEDB driver. Sometimes the date1 field contains a blank date. We need to convert blank date data into a null. But when we run the following code, any blank date comes back as the date '12/30/1899' instead of a NULL.
>
>How can we convert blank dates into nulls using the following?
>
>
>OConn = CREATEOBJECT("ADODB.Connection")
>OConn.ConnectionString = "provider=vfpoledb.1;;
>	data source=c:\\mydata\;Exclusive=false;Nulls=false"
>OConn.Open
>
>cSQL = "select id, name, IIF(EMPTY(date1),  null, date1) AS date1 from mytable WHERE id = myid' ORDER BY id"  &&does not work
>cSQL = "select id, name, IIF(EMPTY(date1),  {}, date1) AS date1 from mytable WHERE id = myid' ORDER BY id"  &&Date1 = 12/30/1899
>oRS = OConn.Execute (cSQL)
>
>oRS.Close
>OConn.Close
>
>
>Thanks,
>
>Jerry
cSQL = 'select id, cast(evl(date1,null) as date) as date1 from mytable where id = ?'
It would look like:
OConn = CREATEOBJECT("ADODB.Connection")
OConn.ConnectionString = "provider=vfpoledb;data source=c:\mydata"

OConn.Open()
cSQL = "select id, cast(evl(date1,null) as date) as date1 from mytable where id = ?"

Local loCmd as 'adodb.command', loParm As 'ADODB.Parameter'
loCmd = CREATEOBJECT('AdoDb.Command')
loCmd.ActiveConnection = oConn
loCmd.CommandText = m.cSQL	
loParm = loCmd.CreateParameter('p1')
loParm.Direction=1
loParm.Type = 3  && adInteger
loCmd.Parameters.Append( loParm )

loParm.Value = 1
oRS = loCmd.Execute()
* do whatever
oRS.Close

OConn.Close
You are saying 'from SQL server'. Are you using linked server? If so then using OpenQuery is easier. Check this for a sample:
http://social.msdn.microsoft.com/forums/en-US/visualfoxprogeneral/thread/b7e9e6a9-56ba-4701-bf2e-96de4b6a16cd/

Or from VFP (or .Net) the fastest way I have found is to use .Net's SqlBulkCopy class, check this:
http://www.foxite.com/archives/cursor-adapter-0000207817.htm

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform