I have to do a SQL Server 'job' scheduled for every day at 10 in the morning. The Work would be based on dump the data of a table of a database of a server in other 2 tables (with operations of by means) in another database of another server.
I do not know how to go through all the records, I understand that loops for
and foreach
do not exist in SQL. The access to other servers I think have it controlled. They are linked and lets me access their data but not insert (I guess it is because it is another server, it will be read only, I do not know). The idea would be something like this:
--TABLA_FINAL1
INSERT INTO [BDFINAL].[dbo].[TABLA_FINAL1]
SELECT
campo1_tablaDN16,
campo1_tablaDN16,
'Parametro fijo',
@ParametroCalculado,
campo1_tablaDN16,
...(otros)
FROM [192.168.1.15].[BD_BASE].[dbo].[TABLA_BASE];
--TABLA_FINAL2
INSERT INTO [BDFINAL].[dbo].[TABLA_FINAL2]
SELECT
campo1_tablaDN16,
campo1_tablaDN16,
'Parametro fijo',
@ParametroCalculado,
campo1_tablaDN16,
...(otros)
FROM [192.168.1.15].[BD_BASE].[dbo].[TABLA_BASE];
I do not know if the syntax would be correct, of course I mark error in the fields and that would serve if it were a single record, the idea would be to dump all (those that meet a certain condition). Any ideas?