Questions tagged [varbinary]

varbinary is the SQL Server datatype used to hold variable-length binary data

SQL Server's varbinary datatype is declared with a length specification in the CREATE TABLE statement:

CREATE TABLE tablename (..., colName varbinary(n), ...)

where n is the maximum size of the column in bytes (limited to a maximum of 8000), or the word MAX if more than 8000 bytes might need to be stored. (The absolute maximum size is approximately 2gb as of this writing; consult SQL Server documentation for the exact current maximum.)

For more information, see this entry in the SQL Server online documentation.

411 questions
55
votes
6 answers

SQL Server converting varbinary to string

I want to do conversion in T-SQL from a varbinary type to string type Here is an example : First I got this varbinary 0x21232F297A57A5A743894A0E4A801FC3 And then I want to convert it to 21232f297a57a5a743894a0e4a801fc3 How to do this?
strike_noir
  • 4,080
  • 11
  • 57
  • 100
48
votes
9 answers

Script to save varbinary data to disk

I have some varbinary data stored in a table in MS Sql Server 2005. Does anyone have SQL code that takes a query as input (lets say the query guarantees that a single column of varbinary is returned) and outputs the bytes to disk (one file per…
Suraj
  • 35,905
  • 47
  • 139
  • 250
27
votes
2 answers

How to update a varbinary field with a specific value?

Basically I am trying to give a user a certain password so I can test some functionality on a system, as I only have our admin account and I can't play with that I am just picking a random account so I can do my testing. So here is my attempt at an…
shicky
  • 2,076
  • 5
  • 30
  • 44
24
votes
4 answers

What data can be stored in varbinary data type of SQL Server?

I have a table in which the userpassword field have varbinary datatype, So I'm confused that in which form should I save the data into userpassword field because when I save varchar data it gave me error.
Fraz Sundal
  • 10,288
  • 22
  • 81
  • 132
23
votes
2 answers

What is the advantage of using varbinary over varchar here?

A while ago I asked a question about hierarchy/version number sorting in SQL Server. ( How Can I Sort A 'Version Number' Column Generically Using a SQL Server Query). Among the answers that were submitted was this link to a TSQL Coding challenge…
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
21
votes
2 answers

Strategies for checking ISNULL on varbinary fields?

In the past I've noted terrible performance when querying a varbinary(max) column. Understandable, but it also seems to happen when checking if it's null or not, and I was hoping the engine would instead take some shortcuts. select top 100 * from…
Gavin
  • 9,855
  • 7
  • 49
  • 61
19
votes
4 answers

Max real space in a varbinary(max) in SQL Server

I am saving files (any type ) in a SQL table, using a varbinary(max), I find out that the max usage of this datatype is 8000, but what does the 8000 mean? The online documentation says that is 8000 bytes. Does that mean that the maximum size of the…
carlos
  • 815
  • 2
  • 14
  • 27
18
votes
5 answers

Retrieve varbinary value as BASE64 in MSSQL

I'm looking for a way for retrieving Entity Data Model (EDM) from __MigrationHistory table using only T-SQL (so anyone, using Microsoft SQL Server Management Studio only, could do the same). I want to have a valid BASE64 string value. I don't want…
pizycki
  • 1,249
  • 4
  • 14
  • 26
18
votes
4 answers

Is there a big technical difference between VARBINARY(MAX) and IMAGE data types?

I was reading on internet these statements about SQL Server data types: VARBINARY(MAX) - Binary strings with a variable length can store up to 2^31-1 bytes. IMAGE - Binary strings with a variable length up to 2^31-1 (2,147,483,647) bytes. Is there…
Junior Mayhé
  • 16,144
  • 26
  • 115
  • 161
17
votes
2 answers

SQL Server Varbinary(max): select a subset of bytes from the varbinary field

What is the most efficient way of reading just part of the binary data from a varbinary(MAX) field (not using FileStreams) in SQL Server 2008? When writing data to the column the VarBinary.Write() function is available in T-SQL, allowing bytes to…
gmn
  • 4,199
  • 4
  • 24
  • 46
16
votes
1 answer

SQL Server 2005/2008: Insert a File in an varbinary(max) column in Transact-SQL

Is it possible to insert a file in a varbinary(max) column in Transact-SQL? If yes, I would be very please to have a code snippet to at least give me an idea how to do that. Thanks
Yannic
  • 229
  • 1
  • 3
  • 4
14
votes
4 answers

Casting CONTEXT_INFO to varchar and the resulting length

I'm trying to use CONTEXT_INFO to pass a usercode from a stored procedure into a DELETE trigger for table auditing purposes. It all works fine, however I noticed that the length of the usercode saved in the audit table was not correct. Take this…
Brett Postin
  • 11,215
  • 10
  • 60
  • 95
14
votes
6 answers

How do I get fluent nhibernate to create a varbinary(max) field in sql server

How can I get fluent nhibernate to create a varbinary field in a sql server 2005 table that uses a field size of varbinary(max)? At the moment I always get a default of varbinary(8000), which isn't big enough as i'm going to be storing image…
czk
  • 151
  • 1
  • 1
  • 5
13
votes
2 answers

Streaming VARBINARY data from SQL Server in C#

I'm trying to serve image data stored in a VARBINARY(MAX) field in the database using ASP.Net. Right now, the code is filling a data table, then pulling the byte array out of the DataRow and pushing the byte array into the response. I'm wondering if…
mhildreth
  • 401
  • 1
  • 5
  • 11
12
votes
2 answers

Operand Type Clash

I have a long stored procedure and when I execute the procedure I get the following error: Msg 206, Level 16, State 2, Line 1 Operand type clash: varchar(max) is incompatible with sql_variant So to trouble shoot I have printed satetement where the…
peter
  • 2,396
  • 6
  • 24
  • 29
1
2 3
27 28