Skapa en lagrad procedur?
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ImportData] @date varchar(15) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here DECLARE @query AS varchar(MAX) SET @query = 'CREATE DATABASE aug29 USE aug29 BULK INSERT dbo.Table FROM ''\\Drive\Documents\''' + @date + '''-xxx.txt'' WITH (FIRSTROW = 2, FIELDTERMINATOR = ''\t'', ROWTERMINATOR = ''\n'')' EXEC(@query) END
Öppna sedan din databas på SSMS> Programmerbarhet> Lagrade procedurer> Högerklicka på den nyligen skapade lagrade proceduren (ImportData eller vad du nu kallar den)> Utför lagrad procedur.
Användare kan sedan mata in värdet för parametern @date.