nvarchar to binary conversion in sql server

  • Hi,

    I have a small table in which i will be inserting the data.I want to convert this data to binary and store as binary.I tried some approaches but nothin seems to work.This will be live table which will be storing user information as they put in the application .THe table only has 8 columns so pretty small.

    I am just looking for some way to convert to binary usising T-sql.

    Any help is appreciated.

  • here's the example i always reference from my snippets:

    DECLARE @var VARBINARY(128),

    @res NVARCHAR(64)

    SET @var = CAST(N'Hello World' AS VARBINARY(128))

    PRINT @var

    --results: 0x480065006C006C006F00200057006F0072006C006400

    SET @res = CAST(@var AS NVARCHAR(64))

    PRINT @res

    --results: Hello World

    --The same but using CONVERT:

    SET @var = CONVERT(VARBINARY(128), (N'Bananas and Oranges'))

    PRINT @var

    --results: 0x420061006E0061006E0061007300200061006E00640020004F00720061006E00670065007300

    SET @res = CONVERT(NVARCHAR(64),@var)

    PRINT @res

    --results: Bananas and Oranges

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply