Buat Prosedur Tersimpan?
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
Kemudian pada SSMS buka database> Programmability> Stored Procedures> Klik kanan pada Stored Procedure yang baru dibuat (ImportData atau apa pun namanya)> Execute Stored Procedure.
Pengguna kemudian dapat memasukkan nilai untuk parameter @date.