开发者

How to pass array as varbinary in mssql?

开发者 https://www.devze.com 2023-02-22 11:54 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消