September 12, 2018 at 5:10 pm
Hi all,
I have two queries in access
* Collect data from which two text boxes supply the date range conditions: To and From.
* Cross cross tab query based on the first query. This query is used to supply the information for an excel report.
Connected to SQl linked tables, these queries are slow and cumbersome. I was considering putting them into SQL as views.
However, my understanding is that SQL views don't accept parameters and stored procedures don't return select statements.
So can anybody provide me with some examples of how this could work. If you need more information, please feel free to ask.
Cheers
September 12, 2018 at 6:09 pm
Stored procedures do return select statements so you options are a stored procedure or a table valued function.
September 12, 2018 at 6:14 pm
Views don't accept parameters, but stored procedures do.
Jeff Moden has some articles on doing crosstabs in T-SQL... You can use PIVOT too.
Here's an article...
CREATE PROC myProc
@FromDate DATE,
@ToDate DATE
AS
SELECT...
FROM ...
WHERE SomeDate>=@FromDate AND SomeDate<=@ToDate;
September 13, 2018 at 12:40 am
Given the choice, I'd opt for a Table Valued Function over a Stored Procedure if possible. Yes SPs do return the results of Select statements and if all that matters is getting the results into Excel it probably won't matter. However if you decide later you need to combine it with some other data source, it's a lot easier to do with a TVF than with an SP as there isn't really a "clean" way of getting the result set from an SP from within SQL itself.
September 13, 2018 at 7:48 am
Joe Torre - Wednesday, September 12, 2018 6:09 PMStored procedures do return select statements so you options are a stored procedure or a table valued function.
To be technical, they don't return select statements, they return result sets.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
September 13, 2018 at 8:41 am
andycadley - Thursday, September 13, 2018 12:40 AMGiven the choice, I'd opt for a Table Valued Function over a Stored Procedure if possible. Yes SPs do return the results of Select statements and if all that matters is getting the results into Excel it probably won't matter. However if you decide later you need to combine it with some other data source, it's a lot easier to do with a TVF than with an SP as there isn't really a "clean" way of getting the result set from an SP from within SQL itself.
I agree... if you can pull it off, iTVFs can be quite superior to stored procedures and views.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply