Automatically Populating Data

  • Hi,

    Can anyone advise me of a way to create a loop when populating data.

    INSERT INTO [GHG-RMU-REP2].[Quality_Dashboards].[dbo].[tbl_qd_audit]

    SELECT D.CCG, E.*

    FROM (

    SELECT REPLACE([Organisation Code],'Q72','13Q') AS CCG

    FROM [GHG-RMU-REP2].[References].[dbo].[tbl_English_PCT]

    GROUP BY REPLACE([Organisation Code],'Q72','13Q')

    ) D

    CROSS JOIN (

    SELECT

    [Month] = '2015-09-01',

    Value = '0',

    Measure = 'SEN-06',

    Inserted = GETDATE(),

    Specialty = NULL,

    [S_Flag] = 'N'

    ) E

    I need it to go through and do the same for different months 2015-04-01 to 2015-10-01 and also measures SEN-01 to SEN-06.

    Is this at all possible?

    Thanks in advance.

  • Yes, it's do-able, but there are a number of questions that immediately come to mind... First, you need a simple calendar table, which you can create in a CTE. Second, are you going to use a value of zero for each of the measures? What is the expected set of inserted values? As we don't have your existing tables to work with, we have no way to know what impact that CROSS JOIN is going to have beyond pairing every record in the second select with every record in the first FROM clause. Please go into the details, as they usually matter...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply