Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

convert query to UDF

Posted on 2013-01-08
2
169 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
ID: 38757855
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
ID: 38759152
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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