Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binary or blob data type
Message
From
10/04/2019 01:46:17
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01668007
Message ID:
01668038
Views:
74
Likes (2)
>One more question on the varbinary column/field in the SQL Server
>
>If I want the default of the varbinary field to be empty but not null, would the value of 0 (zero) be the right type of default? That is, when a user retrieves the value in the varbinary field and cast it to a char type, the result is an empty string (of course if there was never a value set in the field).
>
>TIA

Dmitry,

On the SQL Server side, you should use 0x, which is the equivalent of VFP's 0h (the representation of an empty binary string).

Let m.ODBC be an active connection handle to your server:
CURSORSETPROP("MapBinary",.T.,0)

LOCAL SQLStmt AS String

TEXT TO m.SQLStmt NOSHOW
DECLARE @Tmp TABLE (Col1 Int, Col2 Varbinary(10) not null default 0x);

insert into @Tmp (Col1) values (1);
insert into @Tmp (Col1, Col2) values (2, 0xffff);

select * from @Tmp;
ENDTEXT

SQLEXEC(m.ODBC, m.SQLStmt, "curResult")

SELECT *, LEN(Col2) FROM curResult INTO CURSOR curInspect

BROWSE
The result will be as you can see in the attached image,
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform