I'm trying to put together a file with scripts that I can use to create tables, views, procedures, and functions from one server to another. I also run these daily to refresh the data in this schema, because the INSERT_INTO procs look at another schema for what they do, which is prepare the data for reports.The problem is that I have some functions for formatting names and such that I would like to create, also. The INSERT_INTO procs call the name formatting function. Is it possible to create a function from inside a procedure? Like:USE [dbname];GOSET ANSI_NULLS ON;GOSET QUOTED_IDENTIFIER ON;GOCREATE PROCEDURE CREATE_fn_NAME_FORMATTINGAS CREATE FUNCTION fn_NAME_FORMATTING() (@FULLNAME varchar(50)) RETURNS varchar(50) AS BEGIN DECLARE @NAME VARCHAR(50) SET @NAME = [STUFF] RETURN @NAME END EXEC DBO.FN_TESTING2ENDGO
This is just off the top of my head as an example. Below is what I want to be able to do, so I can just EXEC DBO.CREATE_ALL_STUFF.USE [dbname];GOSET ANSI_NULLS ON;GOSET QUOTED_IDENTIFIER ON;GOCREATE PROCEDURE [dbo].[CREATE_ALL_STUFF]ASEXEC DBO.CREATE_A_TABLEEXEC DBO.CREATE_C_TABLEEXEC DBO.CREATE_E_TABLEEXEC DBO.CREATE_P_TABLEEXEC DBO.CREATE_S_TABLEEXEC DBO.CREATE_vw_DSA_MILESTONE_REMARKSEXEC DBO.CREATE_MILESTONE_REMARKS_TABLEEXEC DBO.CREATE_CASES_ALL_TABLEEXEC DBO.CREATE_fn_NAME_FORMATTING -- <--- that's the one I want to createEXEC DBO.INSERT_INTO_CASES_ALLEXEC DBO.INSERT_INTO_MILESTONE_REMARKSEXEC DBO.INSERT_INTO_AEXEC DBO.INSERT_INTO_CEXEC DBO.INSERT_INTO_EEXEC DBO.INSERT_INTO_PEXEC DBO.INSERT_INTO_SEXEC DBO.CREATE_vw_AEXEC DBO.CREATE_vw_CEXEC DBO.CREATE_vw_EEXEC DBO.CREATE_vw_PEXEC DBO.CREATE_vw_SGO
Is this possible?