0

please i need your help i have two tables the first one is full with all calendar data dim_table_start(pk_date_deb,year,month,trimester,week,date) and i want to fill the second table with data from dim_data_start dim_table_end(pk_date_fin,year,month,trimester,week,date) i tried :

INSERT INTO [bd_disponibilite].[dbo].[dim_date_fin]
           ([PK_Date_fin]

           ,[Year]

           ,[Trimester]

           ,[Month]

           ,[Week]
        )
     VALUES
         (select * from dbo.dim_date_Debut)

but doesn't work

how can i add all data table to fill the second table thank you

2 Answers 2

3

You don't need the VALUES portion when inserting records using SELECT:

INSERT INTO [bd_disponibilite].[dbo].[dim_date_fin]
           ([PK_Date_fin]
           ,[Year]
           ,[Trimester]
           ,[Month]
           ,[Week]
           )
SELECT * 
FROM dbo.dim_date_Debut
Sign up to request clarification or add additional context in comments.

2 Comments

Thank yo very much for help
@Goat CO is correct. I'd just like to add some useful info. If you are only doing this insert once it's fine, but if you plan to re-use it I would be specific about the columns you are selecting instead of using Select *. It future proofs your code against somebody adding a column to the schema of dim_date_Debut, which would break your insert. I see this kind of bug a lot.
0

If the destination doesn't exist yet, you can also use SELECT * INTO dbo.dim_date_fin from dbo.dim_date_Debut

This is speedier to code because it copies the schema as well.

If the table exists or needs different properties, Goat's answer is better.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.