0

With this stored procedure (SQL Server):

ALTER PROCEDURE [dbo].[fill_table1]
    @CreatedBy nvarchar(max) = NULL
AS
BEGIN
    SET NOCOUNT ON;

    SELECT
        [IdExchangeRate] = NEWID(),
        [ExchangeRateCode] = 'EUR',
        [ExchangeRatePeriodStartDate] = period,
        [ExchangeRatePeriodEndDate] = EOMonth(period),
        [ExchangeRateValue] = B.Value,
        [CurrencyCode] = A.[Currency Code],
        [CreatedBy] = 'string',
        [CreatedAt] =  GETUTCDATE()
    FROM
        [TempExchangeRates] AS A
    CROSS APPLY
        (SELECT
             period = TRY_CONVERT(date),
             Value = TRY_CONVERT(float, value) 
              ......) B
END

I want to insert this output (+100rows) into another table (table2). I tried but it inserts just one row.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
nada
  • 21
  • 1
  • 7
  • i edit my question. thank u – nada Mar 10 '20 at 21:11
  • What does "for now it's insert just one line" mean? There is nothing being inserted anywhere in this code. It is just a select statement. – Sean Lange Mar 10 '20 at 21:24
  • yes iit' s just a select when i add insert into[table2] Values ( , ,) it's insert just one line with NULL – nada Mar 10 '20 at 21:25
  • Well....if you are using VALUES it will insert one line. That is how it works. You would want to use the select statement here INSTEAD of a VALUES clause. Share your insert statement and I can show you. – Sean Lange Mar 10 '20 at 21:29
  • Or check out the documentation for the INSERT statement. https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql?view=sql-server-ver15 – Sean Lange Mar 10 '20 at 21:30
  • Or this question...https://stackoverflow.com/questions/25969/insert-into-values-select-from – Sean Lange Mar 10 '20 at 21:30
  • But i have one question plz, using insert into.. value(@) those values must be declared!! in my case i don't need to insert those values because i alredy had them ... this is why i did'nt understand how i do that – nada Mar 10 '20 at 21:34
  • for the second link, me i don't have a table it's just the output of a stored procedure. – nada Mar 10 '20 at 21:36
  • ur right it's works ..thank u so much – nada Mar 10 '20 at 21:39

1 Answers1

0

Thanks very much for @Sean Lange comment. It helped me so much.

I add that before select

 INSERT INTO [dbo].[table2]
       ([column1]..
       ,[columnsn]
       )
nada
  • 21
  • 1
  • 7