Jordan Pan
Jordan Pan

Reputation: 23

How to write values to table?

We create a ASA job, in the query we want to create a table and write some values to the table, the values is our aggregation value.

e.g.

CREATE TABLE Temp ( [Key] nvarchar(max), UtcTimestamp datetime, Value nvarchar(max) );

select 'Key1' as [Key], system.timestamp as UtcTimestamp, 'value1' as Value into Temp from input select 'Key2' as [Key], system.timestamp as UtcTimestamp, 'value2' as Value into Temp from input

but it will make an error: duplicate output names are not allowed " temp", so how to write more values into the table 'Temp' ?

We can use the specified output only once in our query, is there anyway we can write more values to one output?

Upvotes: 0

Views: 413

Answers (1)

Aλeᵡ
Aλeᵡ

Reputation: 491

Nothing is "created" as a result of CREATE TABLE statement in ASA, it is just a way to specify simple input schema. Therefore it can not be used for the output only inputs.

You can however just union result of two query statements like this:

SELECT 'Key1' AS [Key], System.Timestamp AS UtcTimestamp, 'value1' AS Value
INTO output
FROM input
UNION
SELECT 'Key2' AS [Key], System.Timestamp AS UtcTimestamp, 'value2' AS Value
FROM input

Note the into being used only once, and UNION is unlike SQL doesn't distinct values.

Upvotes: 1

Related Questions