yznwx
yznwx

Reputation: 33

Insert multiple row to table in firebird

I added one thousand rows to one of my tables while working on SQL Server, I used something like:

DECLARE @cnt2 INT = 0;
WHILE @cnt2 < 1000
BEGIN
    insert into [MyDB].[dbo].[Table] (ID, LastName, FirstName, StreetAddress, City, ZipCode, PhoneNumber, Email, EnteringDate, GroupID)
    values (00+ Convert(varchar(5), @cnt2), 'StudentLastName-' + Convert(varchar(5), @cnt2), 'FirstName', 'Street',  'City', 'xx-xxx', '500-000-000', '[email protected]', GETDATE(), 0, 1)
    SET @cnt2 = @cnt2 + 1;
END;

And it works correctly, but I must have similar code to insert values during using Firebird.

Could you help me with this?

Upvotes: 2

Views: 3441

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 109239

The equivalent for this in Firebird would require an execute block (an anonymous procedure), or a stored procedure.

The code would be something like:

execute block as
declare variable cnt2 integer = 0;
begin
    while (cnt2 < 1000) do
    begin
        insert into Table (ID, LastName, FirstName, StreetAddress, City, ZipCode, PhoneNumber, Email, EnteringDate, GroupID)
        values ('00' || :cnt2, 'StudentLastName-' || :cnt2, 'FirstName', 'Street',  'City', 'xx-xxx', '500-000-000', '[email protected]', CURRENT_DATE, 0, 1);
        cnt2 = cnt2 + 1;
    end
end

Upvotes: 4

Related Questions