473,769 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Make and save a blob on the fly in stored proc

Is there a way to run query, make file out of query (txt,csv or xls -
for example) and save it as a blob into the table column type
Image/Text?

Any thoughts would be greatly appreciated.

Thanks!

Jul 7 '06 #1
5 2052
natzol (na******@thehu manequation.com ) writes:
Is there a way to run query, make file out of query (txt,csv or xls -
for example) and save it as a blob into the table column type
Image/Text?
If you are on SQL 2005 you can create an XML document and save it a
column of the xml datatype or possibly nvarchar(MAX). (Don't use
image/text on SQL 2005 in new code, as these types have been deprecated.)

On SQL 2000, the answer is no.

If you describe the real business problem, we might be able to provide
alternate solutions.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 7 '06 #2
We do use SQL 2000 + VB.NET.

There is a way to create a file via O-SQL and drop it to the server
folder. But how to upload(save) this file content into the table via
stored proc? Is that possible at all?

--=============== =============== =============== =========
--1 step: run the query (Northwind database sample query)
select * from dbo.employees

--=============== =============== =============== =========
--2nd step: make a file stored on the server:

DECLARE @trenutniRed varchar(30),
@tableRow1 varchar(3000),
@sql varchar(300),
@firstColumnNam e varchar(30),
@fileURL varchar(1000),
@columnNumber varchar(30),
@fs int,
@ole int,
@file int,
@TmpStr1 varchar(200)

-- clean up old
SELECT @sql = 'del '+ @fileURL
EXECUTE @ole = sp_OACreate 'Scripting.File SystemObject', @fs OUT
EXEC master..xp_cmds hell @sql, NO_OUTPUT
EXECUTE @ole = sp_OAMethod @fs, 'OpenTextFile', @file OUT, @fileURL,
8, 1
-- make a local file
DECLARE SysKursor INSENSITIVE SCROLL CURSOR
FOR select * from dbo.employees
FOR READ ONLY
OPEN SysKursor
FETCH NEXT FROM SysKursor INTO @tableRow1
WHILE @@Fetch_Status = 0
BEGIN
EXECUTE @ole = sp_OAMethod @file, 'WriteLine', Null, @tableRow1
FETCH NEXT FROM SysKursor INTO @tableRow1
END
CLOSE SysKursor
DEALLOCATE SysKursor
EXECUTE @ole = sp_OADestroy @file
EXECUTE @ole = sp_OADestroy @fs

--=============== =============== =============== =========
3rd step: load file content into the table column text/image
............... ??

Jul 10 '06 #3
natzol (na******@thehu manequation.com ) writes:
We do use SQL 2000 + VB.NET.

There is a way to create a file via O-SQL and drop it to the server
folder. But how to upload(save) this file content into the table via
stored proc? Is that possible at all?
I need to ask: what is the purpose of this? It sounds to me like a very
funny thing to do. Thus, I suspect that there is a better solution, if I
only knew what business problem you are trying to solve.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 10 '06 #4
ok, the last try:

".NET application must provide the functionality to save output files
from stored procs (reports), that are running either inside the jobs or
either as a single call of the web-user, into the database as blobs."

Jul 10 '06 #5
natzol (na******@thehu manequation.com ) writes:
ok, the last try:

".NET application must provide the functionality to save output files
from stored procs (reports), that are running either inside the jobs or
either as a single call of the web-user, into the database as blobs."
You keep repeating yourself. The only clue I get when I read this is
that it appears to be take from a requirement specification. What I
wanted to know was the business reason for doing this.

But my reading of the above, does not match well what you are trying
to do. Having a stored procedure that writes data to a file, is just
plain silly. You need to run a cursor over the result set, and performance
will be ugly.

The reasonable interpretation of the above is that the client should
call the stored procedure, produce a report on file, and then save that
file somewhere, for instance in the database.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 10 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3637
by: Matt | last post by:
I could use some help dealing with null blobs. I'm returning a transaction from an Image BLOB field in SQL Server 2000 using C#. If the transaction exists the value is returned with out trouble, but because the ID can exist without having a value in the Image column the returned value is NULL and the code can't handle it and I receive this error when the Stored Procedure's value is returned (the line of code is marked with "**HERE**": ...
3
1848
by: Hrvoje Voda | last post by:
How to insert a blob arraylist into database? I know it's not good, but my customers want that, so if someone has some simple example of how to do it... Hrcko
14
1835
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage, which would you choose and why? Reason I ask is I created a webpage which essentially runs through a litany of loops to determine which stored proc to kick off. This is written in the code-behind. It occurred to me that I could probably just...
1
2995
by: Basic | last post by:
Hi geeks, I have to transfer some blobs objects from one table to another depending on certain condition. I am using a Stored procedure for this. The snippet of the stored procedure which does this is as below UPDATE F_PITBINARY SET BINARYDATA = LOCOPY(BINARYDATA,'DPPITBINARYDATA','BINARYDATA') WHERE ID = v_id and FPIT.ID = v_fpit_id
4
9181
by: xAvailx | last post by:
Hello: I didn't find any documentation that notes save point names are case sensitive, but I guess they are... Stored Proc to reproduce: /* START CODE SNIPPET */ If Exists (Select * From sysobjects Where Type = 'P' and Name =
0
3872
by: Biztalk Migration | last post by:
I am new to using BLOB with oracle stored proc. I dont knw how to set the size of the buffer which seems to overflow no matter what i used to pass it. I am getting an error System.Data.OracleClient.OracleException: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at "APPS.XXVAA_E_RECRUITMENT_HA_IF", line 13 ORA-06512: at line 1
0
2413
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I can't save the jpg file as a BLOB field using this Method (I'm calling a Stored Procedure): Private Sub save_BLOB(ByVal Photo As Byte())
2
6534
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the...
9
8002
by: matt | last post by:
hello, im doing my first ASP.NET app that inserts & retrieves files from Oracle (no need for a discussion on *that*!). i learned first-hand of the somewhat awkward technique for inserting binary data into an Oracle BLOB column via ADO.NET. since my files are larger than 33k, it seemed had to use this technique: http://support.microsoft.com/default.aspx?scid=kb;en-us;322796
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.