FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to write NULL to a Sql table
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 01:51 AM

To All

How do I write NULL to a numeric or a nvarchar field on a Sql Server table .. when I do this :

oRsFac:Fields("permnum"):Value := if(i->permnum = 0, '', i->permnum )

"permnum" is a nvarchar(255) and i->permnum is numeric 10,0 .. The if() statement writes a zero to the SQL table and not the '' or NULL value ..

Same problem when I test for a char field and want to write NULL to the SQL table ..

Any Ideas ??

Thanks
Rick Lipkin

Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 02:06 AM

Rick:

A silly question

Do you have defined the field to accept NULL?

Regards

SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 3358
Joined: Fri Oct 07, 2005 08:20 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 02:32 AM
Rick:

With this sample I have no problem

Code (fw): Select all Collapse
LOCAL nValor    := 10.50
// The field "UNI_USU" is VARCHAR(10) NOT NULL Type
oRsUni:Fields("UNI_USU"):Value := IIF(nValor = 0.00,'',nValor)
oRsUni:UpDate()


Neither with this an other example I have no problem neither

Code (fw): Select all Collapse
LOCAL nValor    := 10.50
oRsUni:Fields("UNI_USU"):Value := IIF(nValor > 0.00,'',nValor)
oRsUni:UpDate()


Regards
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 03:05 AM

To All

YES .. all the fields are marked to accept 'null' .. for some reason on SQL Server the in line if() does not seem to want to accept '' as null ( for me ) ..

I have in the mean time used a regular if statement and only append a field if it is NOT null .. leaving the field NULL where it needs to be .. a lot of extra code :(

Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 07:58 AM
Rick Lipkin wrote:oRsFac:Fields("permnum"):Value := if(i->permnum = 0, '', i->permnum )


Try

Code (fw): Select all Collapse
oRsFac:Fields("permnum"):Value   := if(i->permnum = 0, , i->permnum )


EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 08:30 AM
Rick,

as SQL Statement you could write something like
Code (fw): Select all Collapse
UPDATE fac SET permnum = null WHERE permnum = 0


On the recordset it might then look like:
Code (fw): Select all Collapse
oRsFac:Fields("permnum"):Value := if(i->permnum = 0, nil, i->permnum )
   or
oRsFac:Fields("permnum"):Value := if(i->permnum = 0, null, i->permnum )

but I don't know if it works on the recordset
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 02:43 PM

To All

oRsRel:Fields("qualified_ind"):Value := if(i->qualify = " ", , )
oRsRel:Fields("qualified_ind"):Value := if(i->qualify = " ", nil ,nil )

Both expressions should return NULL and what happends in MS Sql server the field is just appends blank spaces ..

Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 03:17 PM

Works fine here using latest xHarbour from CVS.

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 03:30 PM

Enrico

Using FWH 811 and the xHarbour build 1.1.0 rev 6195 .. the database is MS Sql Server .. not any other sql flavor.

Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to write NULL to a Sql table
Posted: Tue Apr 21, 2009 07:58 PM

Perhaps you should try with latest xHarbour from CVS.

EMG

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to write NULL to a Sql table
Posted: Wed Apr 22, 2009 02:56 AM
The solution I found long time back and working for me for assigning NULL to fields or parameter values.
Code (fw): Select all Collapse
#xtranslate NULL =>   VTWrapper( 1, nil ) 
...
...
// usage:
oRs:Fields(n):Value := NULL
oCmd:Parameters( n ):Value := NULL

I have not checked with the latest version of xHarbour, if assigning NIL has the same effect. If this works then its a lot better.
Regards



G. N. Rao.

Hyderabad, India
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: How to write NULL to a Sql table
Posted: Wed Apr 22, 2009 07:11 PM

Rao

YES ..

xtranslate NULL => VTWrapper( 1, nil )

Was the answer !!

Thanks
Rick Lipkin

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to write NULL to a Sql table
Posted: Wed Apr 22, 2009 07:38 PM

It seems you are using an old version of win32ole.prg.

EMG

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: How to write NULL to a Sql table
Posted: Wed Apr 22, 2009 08:18 PM

Enrico

Using the official binaries from FTDN for xHarbour 409 .. not linking in anything else .. and it appears the FTDN version has a newer build revision than xHarbour.org :(

Rick

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: How to write NULL to a Sql table
Posted: Wed Apr 22, 2009 08:45 PM

Sorry, I'm running out of ideas... :-(

EMG