Asif Ganaie
Asif Ganaie

Reputation: 101

How to select Id one by one to select from other tables using the Ids

//Issue: want to select multplple Id and insert in tables uisng those Ids.

Declare @Id varchar(100),@Sorder varchar(100),@Sorder1 varchar(100),@Sorder2 varchar(100),@attrId varchar(100) Set @Id=(select ID from [BB_INTERFACE].[dbo].[tbl_task_configuration_desc] where title in('MWI Backhaul WSIPT TrunkGroup', 'MWI Backhaul WSIPT New Number Range', 'MWI Backhaul WSIPT Presentation Number Range', 'MWI Interconnect Router Configuration', 'MWI Emergency Contact', 'MWI GVA POP Allocation', 'MWI GVA POP Configuration', 'MWI Backhaul WSIPT Trunk', 'MWI Handover Service', 'MWI CPOD VLAN Allocation', 'MWI CPOD VLAN Information', 'MWI Handover Service Customer Group', 'MWI Handover Service EMC Multichannel', 'MWI Avaya GVA Information', 'MWI Backhaul Ethernet Information', 'MWI Handover Service Interconnect Router', 'MWI Handover Service Contact Centre', 'MWI Handover Service WFO Call Recording', 'MWI Handover Service Unified Comms', 'MWI Handover Service New Number Range', 'MWI CPOD VLAN Allocation Group') ) Set @Sorder=(select max(ScreenOrder) from [BB_INTERFACE].[dbo].[tbl_task_configuration_data] where taskcodeId in (@Id) )
set @Sorder1=@Sorder+1 set @Sorder2=@Sorder1+1

--select @Id as Taskid,@Sorder as lastScreenorder,@Sorder1 as NewSorder1,@Sorder2 as NewSorder2 // issue only one Id,@Sorder1,@Sorder2 is able to select here

Insert into [BB_INTERFACE].[dbo].[tbl_task_configuration_data] (TaskCodeid,AttributeName,DisplayName,Visibility,Description,ScreenOrder,Control,ModifyDate,Ein,Editable,Validation,Manual,IsHighlighted,RowNum,ExtendWidth,ChargeAttribute,EditableInJourney,Parent) values (@id,'crfReference','crfReference','1','crfReference',@Sorder1,'TEXTBOX',Getdate(),'0','0','1','0','0','1','0','0','ALL','1'), (@id,'productVariant','productVariant','1','productVariant',@Sorder2,'DropDown',Getdate(),'0','0','1','0','0','1','0','0','ALL','1') set @attrId=(select Id from [BB_INTERFACE].[dbo].[tbl_task_configuration_data] where taskcodeId in(@Id) and AttributeName='productVariant' and control='DropDown') insert into [BB_INTERFACE].[dbo].[tbl_task_configuration_data_dropdown] (TaskCodeId,AttributeId,AttributeValue,[Enable],AttributeText) values(@id,@attrId,'ACS Premium','1','ACS Premium'), (@id,@attrId,'ACS Select','1','ACS Select'), (@id,@attrId,'ACS DI','1','ACS DI')

// Requirement: how to make it dynnamic by geting the Ids and uisng those ids get the values and insert into the two tables...kindly help in that issue

Upvotes: 1

Views: 97

Answers (2)

Md. Suman Kabir
Md. Suman Kabir

Reputation: 5453

You can follow this approach:

IF object_id('#TASKID') is not null
    drop table #TASKID

SELECT id INTO #TASKID
       FROM [BB_INTERFACE].[dbo].[tbl_task_configuration_desc]
       WHERE title IN ('MWI Backhaul WSIPT TrunkGroup',
                       'MWI Backhaul WSIPT New Number Range',
                       ... long list of string constants .....
                       'MWI Handover Service New Number Range',
                      'MWI CPOD VLAN Allocation Group')
         AND LOB = 'AVAYA bto L2C'

SELECT *
FROM [BB_INTERFACE].[dbo].[tbl_task_configuration_data]
--where AttributeName like'%Product Variant%'
WHERE taskcodeId IN (select id from #TASKID)

SELECT TOP 10 *
FROM [BB_INTERFACE].[dbo].[tbl_task_configuration_data_dropdown]
WHERE taskcodeId IN (select id from #TASKID)

Explanation : Insert the IDs in a temp table with the select query you have following this select * into new_table from old_table, and then use that temp table in your further queries like this WHERE taskcodeId IN (select id from #TASKID)

Upvotes: 0

TheGameiswar
TheGameiswar

Reputation: 28930

 Set @TASKID=( select id from [BB_INTERFACE].[dbo]. //get ids [tbl_task_configuration_desc] 
    where title in 

Your ID may return multiple values and in this above code will fail..

so i recommend putting this into some temp table

create table #temp
(
id int
)
insert into #temp
<<your select query>>

and finally use the above temp table in place of taskid for later queries

Upvotes: 0

Related Questions