473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to get a SQL UDF to return image data type???

Explanation:
We have several SP that need to retrieve a single "Default Photo" from one
of several Photo tables. The column in question in these tables is defined as
an IMAGE data type. I currently have a SP that that return the default photo
and other relative information.

Several of my developers want to retrieve only the image column from this
SP. So I thought Id create a function that would execute code very similar to
the SP version and only return the image data. This way they could use the
function inside of a select statement without the need to inner join all the
needed tables.

Issue:
Problem is that SQL function does not allow a return type of IMAGE (don’t
know why, love to hear a reason on that one). So ok, I thought, lets return
the image as BINARY and do a CONVERT(image, dbo.MyBinaryData()). These
function executes but any result comes back as 0xFF or NULL. Id expect NULL
if no default photo was ever set, so that’s cool, it’s the ones where it
should be returning the entire image that’s the problem

How can I get Image data from a UDF?

--
JP
..NET Software Developer
Aug 3 '07 #1
3 4256
The easiest way is to forget about UDF and just to select that one field

I am not sure what your developers mean though. They can get result set from
your sp and use just this field (column) ignoring the rest if any
additional columns are selected. What is making them unhappy?
"JP" <JP@discussions.microsoft.comwrote in message
news:08**********************************@microsof t.com...
Explanation:
We have several SP that need to retrieve a single "Default Photo" from one
of several Photo tables. The column in question in these tables is defined
as
an IMAGE data type. I currently have a SP that that return the default
photo
and other relative information.

Several of my developers want to retrieve only the image column from this
SP. So I thought Id create a function that would execute code very similar
to
the SP version and only return the image data. This way they could use the
function inside of a select statement without the need to inner join all
the
needed tables.

Issue:
Problem is that SQL function does not allow a return type of IMAGE
(don’t
know why, love to hear a reason on that one). So ok, I thought, lets
return
the image as BINARY and do a CONVERT(image, dbo.MyBinaryData()). These
function executes but any result comes back as 0xFF or NULL. Id expect
NULL
if no default photo was ever set, so that’s cool, it’s the ones where
it
should be returning the entire image that’s the problem

How can I get Image data from a UDF?

--
JP
.NET Software Developer

Aug 3 '07 #2
Got it working with UDF. Basically:

DECLARE @image as VARBINARY(max)
SELECT @image = CONVERT(VARBINARY,imagePhoto) FROM table
RETURN @image

--
JP
..NET Software Developer
"AlexS" wrote:
The easiest way is to forget about UDF and just to select that one field

I am not sure what your developers mean though. They can get result set from
your sp and use just this field (column) ignoring the rest if any
additional columns are selected. What is making them unhappy?
"JP" <JP@discussions.microsoft.comwrote in message
news:08**********************************@microsof t.com...
Explanation:
We have several SP that need to retrieve a single "Default Photo" from one
of several Photo tables. The column in question in these tables is defined
as
an IMAGE data type. I currently have a SP that that return the default
photo
and other relative information.

Several of my developers want to retrieve only the image column from this
SP. So I thought Id create a function that would execute code very similar
to
the SP version and only return the image data. This way they could use the
function inside of a select statement without the need to inner join all
the
needed tables.

Issue:
Problem is that SQL function does not allow a return type of IMAGE
(don’t
know why, love to hear a reason on that one). So ok, I thought, lets
return
the image as BINARY and do a CONVERT(image, dbo.MyBinaryData()). These
function executes but any result comes back as 0xFF or NULL. Id expect
NULL
if no default photo was ever set, so that’s cool, it’s the ones where
it
should be returning the entire image that’s the problem

How can I get Image data from a UDF?

--
JP
.NET Software Developer


Aug 4 '07 #3
Yeah , I was going to say look at this:

http://novicksoftware.com/UDFofWeek/...tatypeName.htm

"JP" <JP@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
Got it working with UDF. Basically:

DECLARE @image as VARBINARY(max)
SELECT @image = CONVERT(VARBINARY,imagePhoto) FROM table
RETURN @image

--
JP
.NET Software Developer
"AlexS" wrote:
>The easiest way is to forget about UDF and just to select that one field

I am not sure what your developers mean though. They can get result set
from
your sp and use just this field (column) ignoring the rest if any
additional columns are selected. What is making them unhappy?
"JP" <JP@discussions.microsoft.comwrote in message
news:08**********************************@microso ft.com...
Explanation:
We have several SP that need to retrieve a single "Default Photo" from
one
of several Photo tables. The column in question in these tables is
defined
as
an IMAGE data type. I currently have a SP that that return the default
photo
and other relative information.

Several of my developers want to retrieve only the image column from
this
SP. So I thought Id create a function that would execute code very
similar
to
the SP version and only return the image data. This way they could use
the
function inside of a select statement without the need to inner join
all
the
needed tables.

Issue:
Problem is that SQL function does not allow a return type of IMAGE
(donâ?Tt
know why, love to hear a reason on that one). So ok, I thought, lets
return
the image as BINARY and do a CONVERT(image, dbo.MyBinaryData()). These
function executes but any result comes back as 0xFF or NULL. Id expect
NULL
if no default photo was ever set, so thatâ?Ts cool, itâ?Ts the ones
where
it
should be returning the entire image thatâ?Ts the problem

How can I get Image data from a UDF?

--
JP
.NET Software Developer



Aug 6 '07 #4

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

Similar topics

7
by: me | last post by:
Hey all, well i am also a newbie :) i saw this on many sites: <img src="somephp.php?blabla" width="100"> how can i make that to? i want to reffer to a php file that returns or prints a jpg...
6
by: Spam sucks | last post by:
hello, i want to have an image in a variable so i can show it were ever i want the only catch is that i want the image to be called in the same page, i found this script but the problem is that...
9
by: Ann Huxtable | last post by:
I have the following code segment - which compiles fine. I'm just worried I may get run time probs - because it looks like the functions are being overloaded by the return types?. Is this Ok: ? ...
17
by: gsb | last post by:
HOW TO: Submit a form to PHP with no return? I need to submit a form for file upload to a PHP script but do not want anything returned. That is the TARGET for the form should be like a null...
19
by: Sergey Koveshnikov | last post by:
Hello, If my function return a pointer on a memory area, where do I free it? e.x.: char *foo() { char *p; p = malloc(10); strcpy(p, "something"); return(p); }
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.