|
-
Feb 24th, 2009, 04:40 AM
#1
Thread Starter
Hyperactive Member
Pulling Data into VB From SQL Function
Hello,
I am having a problem that I can't solve and would appreciate any help you can offer.
I have a table in my SQL DB that contains :
- ID
- Date From
- Date To
I then have a SQL function that pulls out the Start Date (See code below)
Code:
CREATE FUNCTION dbo.fn_YearBreakdownDateFrom (@Date datetime)
RETURNS char(10)
AS
BEGIN
DECLARE @RetVal datetime
DECLARE @ConvertedDate char(10)
SET @RetVal = (SELECT DateFrom
FROM dbo.tbl_YearBreakdown
WHERE (DateFrom <= CONVERT(DATETIME, @Date, 103)) AND
(DateTo >= CONVERT(DATETIME, @Date, 103)))
SET @ConvertedDate = CONVERT(Char(10), @RetVal, 103)
RETURN @ConvertedDate
END
NB: The reason for converting the date to a char(10) was because initially I was calling this function from a stored procedure and required the date to be passed in a certain format.
In my VB.NET app I need to call this function and get the Start Date to populate a text box on my form.
However, I don't know how to do this as in the past I've always just called stored procedures which have in turn returned the data from the functions.
Can anyone help me please ?
Thanks in advance
-
Feb 24th, 2009, 08:18 AM
#2
Re: Pulling Data into VB From SQL Function
You can call it using a select statement
SELECT DateFrom
FROM dbo.tbl_YearBreakdown
WHERE (DateFrom <= CONVERT(DATETIME, @Date, 103)) AND
(DateTo >= CONVERT(DATETIME, @Date, 103))
Call using ExecuteScaler on a command object
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|