Hello, I need help with this topic, in the work they have left me a project, to enter users through an excel file and that by selecting a user already registered in the database all their permissions pass to the new users, my problem is when I want to duplicate the permissions of that user in another table, I do not know if they understand me, here is the query that I used:
INSERT INTO tabla1 /*tabla*/
(wgru_id,
wusr_id,
wcli_cod,
wclte_id,
wcli_fecha,
wcli_default)/*campos a los que insertare*/
SELECT wgru_id,
(SELECT TOP (@cantidad_filas) wusr_id
FROM tabla2
ORDER BY wusr_id DESC),
/*estos son los id que quiero recuperar de la otra tabla*/
wcli_cod,
wclte_id,
Getdate(),
wcli_default
FROM tabla1
WHERE wusr_id = @usuario_seleccionado
In this query I want to make one or more duplicates of a record just by changing the field wusr_id, the duplicates depend on the new records that I have inserted, I need to take out all the IDs (wusr_id) and make the query.
It returns the following error
Msg 512, Level 16, State 1, Procedure Mant_spDoubleClient_WordRecords, Line 8 [Batch Start Line 69] Subquery returned more than 1 value. This is not allowed when the subquery follows =,! =, > = or when the subquery is used as an expression.
I hope you can help me, I am new to this online question, GREETINGS.