我需要编写Textprocedure (Table_txt varchar(200))
从表 My_table 中扫描数据的程序例如:我有表
My_table (Id int, Name varchar(200))
我需要像输出文本(脚本)一样的过程执行结果
DELETE FROM My_table
INSERT INTO My_table (Id, Name) values (1, 'Tropico')
INSERT INTO My_table (Id, Name) values (2, 'Bus')
INSERT INTO My_table (Id, Name) values (4, 'Africa')
INSERT INTO My_table (Id, Name) values (8, 'Arrival')
我可以通过程序来做吗?我愿意
CREATE TABLE My_table (Id int, Name varchar(200))
DELETE FROM My_table
INSERT INTO My_table (Id, Name) values (1, 'Tropico')
INSERT INTO My_table (Id, Name) values (2, 'Bus')
INSERT INTO My_table (Id, Name) values (4, 'Africa')
INSERT INTO My_table (Id, Name) values (8, 'Arrival')
ALTER PROCEDURE Textprocedure (@Table_txt varchar(200))
AS
BEGIN
DECLARE @Id1 NVARCHAR(40)
DECLARE @Result NVARCHAR(4000)
SET @Result = ''
SELECT @Result = 'INSERT INTO '+ CAST(@Table_txt AS NVARCHAR(250)) + --@Result
+'() values ' + CAST([name] AS NVARCHAR(250)) + ' ' FROM My_table --where Id<5
PRINT (@Result)
END
GO
EXEC Textprocedure My_table
我的输出:INSERT INTO My_table() values Arrival
但我需要多行的结果。我可以骑自行车吗?我需要打印表参数,如 id、name?但是我该如何挑选它们呢?