Copy data from table to another table

Tabboz 41 Reputation points
2021-07-06T08:44:34.23+00:00

I have two tables, the main one is called [dettaglioMateriale]
112010-tbl-dettagliomateriale.jpg

the second is called [fuoriUso]
112074-tbl-fuoriuso.jpg

through a button I have to copy two columns of the relevant row from the main one to the second one
112131-btn-command.jpg

the colums are IDdettaglio and Note tbl[dettaglioMateriale] , in CODdettaglio and Note tbl[fuoriUso]

the button code that calls two stored procedures is this
112132-sub-command-vb.jpg

the first stored procedure deletes associations to other tables, and works fine
112030-sp-del.jpg

the second stored procedure copies the columns from the first table to the second
112104-sp-copy.jpg

I get the following error, as in the table where the columns are copied there is the Distrutto column (bit) which is a checkboxfield and does not allow null fields
112152-error.jpg

how can i solve the problem?
I also thought about doing an additional INSERT and giving the value FALSE as the default (which would also be right), but I couldn't.

thanks in advance to those who want to help me.

Developer technologies ASP.NET Other
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2021-07-06T09:37:33.38+00:00

    Try this INSERT statement:

    INSERT INTO [dbo].[fuoriUso] ( CODdettaglio, Note, Distrutto )
    SELECT IDdettaglio, Note, 0
    FROM . . .
    

    It is probably better to adjust the table definition, adding the default value for Distrutto column:

    alter table [dbo].[fuoriUso] add constraint somename1 default 0 for Distrutto
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.