Solved

Need help creating a stored procedure

Posted on 2016-09-15
4
59 Views
Last Modified: 2016-09-19
I want to create a stored procedure to then schedule with SQL agent. Never created one before. Help plugging in the select statements below into the stored procedure template will be greatly appreciated.

DROP TABLE DBO.WOYTRN01

SELECT * into WOYTRN01 FROM OPENQUERY(ATQAV, 'SELECT * FROM WOYTRN01 where 1=0')

INSERT INTO WOYTRN01
SELECT * FROM OPENQUERY(ATQAV, 'SELECT * FROM WOYTRN01')

Open in new window



New stored procedure template:
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
	-- Add the parameters for the stored procedure here
	<@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>, 
	<@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO

Open in new window

0
Comment
Question by:maximus1974
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
Pawan Kumar earned 250 total points
ID: 41800829
Here it is

CREATE PROC [ProcName]
AS
BEGIN

	DROP TABLE DBO.WOYTRN01

	SELECT * into WOYTRN01 FROM OPENQUERY(ATQAV, 'SELECT * FROM WOYTRN01 where 1=0')

	INSERT INTO WOYTRN01
	SELECT * FROM OPENQUERY(ATQAV, 'SELECT * FROM WOYTRN01')


END
---

Open in new window

0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41800830
@Author - Please let me know if you need more help on this. Just Replace [ProcName] with the name you want to put it there.
0
 
LVL 50

Assisted Solution

by:Ryan Chong
Ryan Chong earned 250 total points
ID: 41800855
@maximus1974,

DROP TABLE DBO.WOYTRN01

any reason to drop the table: DBO.WOYTRN01 every time you run the stored procedure? Is the column format of the source will always be different?
0
 
LVL 28

Expert Comment

by:Pawan Kumar
ID: 41801053
@Author - Do you need to any more help on this ?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Designer 19 39
Need some help to cast ntext to nvarchar SQL 2000 7 31
SQL Update trigger 5 16
why sql server only update some statistics in the database ? 3 19
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

786 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