I need to pass an array as a varbinary parameter to a ms sql stored procedure using php. I am not sur开发者_如何学运维e how to convert an array into a varbinary or equivalent.
How could I do this?
Thanks
If you are using SQL Server 2016 or newer now you should utilize the varbinary data type.
If you are on an older version then put it into a varchar(max) column and use the below tSQL to convert it from a string back to hex:
SET NOCOUNT ON;
DECLARE @BinaryValue [varbinary](256) ,
@x [xml]
SET @x = '<root></root>;'
SET @BinaryValue = 0x0200CDDBC2A60A08B57EDF7622CA52A45EC3BC234CE6A0F7D038F3BAE0EC00
SELECT N'0x' + @x.value('xs:hexBinary(sql:variable("@BinaryValue"))',
'[varchar](512)')
SET NOCOUNT OFF;
GO
精彩评论