我需要使用convert二进制函数更新一列,但它抛出了一个错误。
这是我的疑问:
update DocumentOnline
set FileData = CONVERT(VARBINARY(max), FileData, 0x255044462D312E340A25E2E3CFD30A322030206F626A0A3C3C2F4C656E6774682034392F46696C7465722F466C6174654465636F64653E3E73747265616D0A789C2BE4720AE1323653B03030530849E1720DE10AE42A54305430004208999CABA01F9166A8E092AF10C80500EAA209F20A656E6473747265616D0A656E646F626A0A342030206F626A0A3C3C2F5265736F75726365733C3C2F584F626A6563743C3C2F586631203120)
where ClientId = '54528' and EndDate = '201607'
这就是错误:
参数数据类型varbinary(max)对于convert函数的参数3无效。
我是SQL的初学者——我错过了什么?
如果FileData
的数据类型是VARBINary(MAX)
,只需使用以下内容:
update DocumentOnline
set FileData = 0x255044462D312E340A25E2E3CFD30A322030206F626A0A3C3C2F4C656E6774682034392F46696C7465722F466C6174654465636F64653E3E73747265616D0A789C2BE4720AE1323653B03030530849E1720DE10AE42A54305430004208999CABA01F9166A8E092AF10C80500EAA209F20A656E6473747265616D0A656E646F626A0A342030206F626A0A3C3C2F5265736F75726365733C3C2F584F626A6563743C3C2F586631203120
where ClientId = '54528' and EndDate = '201607'
你使用了错误的语法转换
https://msdn.microsoft.com/en-in/library/ms187928.aspx
-- Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
update DocumentOnline
set FileData = CONVERT(VARBINARY(max), 0x255044462D312E340A25E2E3CFD30A322030206F626A0A3C3C2F4C656E6774682034392F46696C7465722F466C6174654465636F64653E3E73747265616D0A789C2BE4720AE1323653B03030530849E1720DE10AE42A54305430004208999CABA01F9166A8E092AF10C80500EAA209F20A656E6473747265616D0A656E646F626A0A342030206F626A0A3C3C2F5265736F75726365733C3C2F584F626A6563743C3C2F586631203120)
where ClientId = '54528' and EndDate = '201607'