Solved

convert query to UDF

Posted on 2013-01-08
2
166 Views
Last Modified: 2013-01-09
I received help here in EE to write a query that is working well for my desired results.

I now need to convert the query into a UDF or stored procedure that returns the table results that the query currently produces.

I need help figuring out how to convert the query to a UDF. I do not know how to replace the ;WITH  part of the code when inside a function.


Thank you much.
ee-sql-script.txt
0
Comment
Question by:metropia
2 Comments
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 500 total points
Comment Utility
just wrap your code with something like this:
CREATE PROCEDURE yourProcName
AS
BEGIN
-- all your code here
END

Open in new window

and then when you call it like this it will return the same thing you are getting from the query.
EXEC yourProcName

Open in new window

0
 

Author Comment

by:metropia
Comment Utility
thank you. I was trying to put all the code in a user defined function instead that a stored procedure, and I was getting errors on the line containing the ;WITH
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Record extraction 3 12
SQL query 4 25
T-SQL Using IN with a subquery 3 12
Insert with SET how to handle join 6 26
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now