Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Saving binay data to disk via TSQL???


Saving binay data to disk via TSQL???

Author
Message
flurk118
flurk118
SSC Veteran
SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)

Group: General Forum Members
Points: 205 Visits: 222
Is there a way of saving binary data, retrieved from the database, to disk using just TSQL?
Thanks...
Andras Belokosztolszki
Andras Belokosztolszki
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1387 Visits: 1585
Writing binary data, especially if you want to write out to several files, several objects, ... to disk is a bit of a pain. Your best bet would be to write a small application say in C# Smile.
If that is not an option, have a look at http://www.sqlservercentral.com/articles/Miscellaneous/writingtoafileusingthesp_oacreatestoredprocedurean/1694/

Regards,
Andras



Andras Belokosztolszki, MCPD, PhD
GoldenGate Software
flurk118
flurk118
SSC Veteran
SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)

Group: General Forum Members
Points: 205 Visits: 222
Thanks for the info Andras.

Interesting article.
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45430 Visits: 39942
Andras Belokosztolszki (10/19/2007)
Writing binary data, especially if you want to write out to several files, several objects, ... to disk is a bit of a pain. Your best bet would be to write a small application say in C# Smile.
If that is not an option, have a look at http://www.sqlservercentral.com/articles/Miscellaneous/writingtoafileusingthesp_oacreatestoredprocedurean/1694/

Regards,
Andras


Why aren't you considering BCP with no terminator?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
flurk118
flurk118
SSC Veteran
SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)

Group: General Forum Members
Points: 205 Visits: 222
I have a table with many rows, each containing an binary field containing, basically, an image. I would like to query this table and produce a file on disk for each of the rows.

Is this achievable using BCP?
Jeff Moden
Jeff Moden
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45430 Visits: 39942
Heh... I actually haven't tried it because I won't allow folks to store images in our databases... but I don't see why it wouldn't work... it's just another form of data.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Martin Reyerink-362775
Martin Reyerink-362775
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 14
I have used BCP to archive binary data to disk. You need to specify a format file with no format for this to work.
Nebojsa Ilic
Nebojsa Ilic
SSC-Enthusiastic
SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)SSC-Enthusiastic (163 reputation)

Group: General Forum Members
Points: 163 Visits: 290
Hi, I'm using bcp to queryout images from database and T-SQL code looks something like this:


DECLARE c1 CURSOR FOR
SELECT (KeyField)
FROM (Table)
WHERE ...

OPEN c1

FETCH NEXT FROM c1
INTO @KeyField

WHILE @@FETCH_STATUS = 0
BEGIN

-- Create unique name for the file using KeyField from the table
SELECT @FileName = '(Server path ending with \)' + convert(varchar(18), @KeyField) + '.(ext)'

SET @bcpCommand = 'bcp "SELECT (image) FROM (Table) WHERE KeyField = ' + convert(varchar(18), @KeyField) + '" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -S (ServerName) -T -n'

EXEC master..xp_cmdshell @bcpCommand, no_output

FETCH NEXT FROM c1
INTO @KeyField

END

CLOSE c1
DEALLOCATE c1
flurk118
flurk118
SSC Veteran
SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)

Group: General Forum Members
Points: 205 Visits: 222
Thanks Martin & Nebjosa,

Looks exactly what I need. I will try it.

Ta
flurk118
flurk118
SSC Veteran
SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)SSC Veteran (205 reputation)

Group: General Forum Members
Points: 205 Visits: 222
I have tried the above but have run into an issue.

The table holds an image field containing either tiff, jpg or pdf.
The code works for pdf but the file created for tiff and jpg do not.

Is there a simple reason for this?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search