DECLARE @Quantity FLOAT ,@Destination Nvarchar(100),@Source NVarchar(100),@RawMaterialConfigID INT,@CreatedDate DateTime DECLARE @QtyRcvd TABLE (Quantity FLOAT,CreatedDate DateTime) DECLARE @CokeSilo1 NVarchar(100) SET @CokeSilo1 = 'Coke Silo' INSERT INTO @QtyRcvd EXEC [Mass].dbo.sp_executesql N' SELECT PRD.Quantity as Quantity, PRD.CreatedDate as CreatedDate from PortLogBook.RawMaterialDelivery PRD JOIN PortLogBook.RawMaterialConfig PRC ON PRD.RawMaterialConfigID =PRD.RawMaterialConfigID WHERE PRC.Destination IN (@CokeSilo1) ', N' @Quantity FLOAT output, @Destination Nvarchar(100), @CreatedDate DateTime, @CokeSilo1 Nvarchar(100)' , @Quantity =@Quantity, @Destination = @Destination, @CreatedDate=@CreatedDate, @CokeSilo1 =@CokeSilo1 select * from @QtyRcvd
I have a query like above where I am fetching data from the table of another database via the Linked server "Mass") .
ResultSet1
Now I have another query which will give a result set as follows.
select AR.CampaignID, AR.CokeTypeName, AR.BeginUsagePeriod, AR.EndUsagePeriod from CokeTypesSearch AR
ResultSet2
Now i need to verify any Quantity is present between the BeginUsagePeriod and EndUsagePeriod in ResultSet1 and if its present I need to add as a new Column at the end of ResultSet2 as Quantity against each CampaignID and CokeTypeName.
How can I accomplish this? Please help me out with a solution.
Thanks
-pep