• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

Need help creating a stored procedure

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
maximus1974
Asked:
maximus1974
  • 3
2 Solutions
 
Pawan KumarDatabase ExpertCommented:
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
 
Pawan KumarDatabase ExpertCommented:
@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
 
Ryan ChongCommented:
@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
 
Pawan KumarDatabase ExpertCommented:
@Author - Do you need to any more help on this ?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now