SQL While loop
-
Hi I'm running the below query, I want to get records for multiple fundCodes in this case Bateleur and Tower Fund.I'm only getting records for Bateleur only from 2016-04-20 to 2016-04-29. Thank you
Declare @FundCodes VarChar(Max)='Bateleur|Tower Fund',--Tower Fund
@StartDate DateTime='2016/04/20',
@EndDate DateTime='2016/04/29',
@Zero integer=1,
@LongShortAll integer = 0, --0 for all, 1 for long value, 2 for short value
@PhysEff integer = 0 --0 for physical, 1 for Effective--check the fulldate select fulldate into #TableDates from AssetData.dbo.Calendar cal where cal.FullDate between @StartDate and @EndDate and IsWeekDay = 1 and IsHoliday = 0 -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @NextDate DateTime set @NextDate = @StartDate declare @TempValues table(FundCode varchar(200),EffectiveDate DateTime, Value Float) declare @fundcodestable table (ID int, fundcode varchar(300)) declare @Val float --Date Counter declare @DateCounter int = 0 select @DateCounter = count(Fulldate) from #TableDates declare @Date date while @DateCounter <> 0 begin set @Date = (select top 1 fulldate from #TableDates order by 1) --fundcode insert into @fundcodestable select pn, s from StagedFundReportingData..FnxSplit('|', @fundcodes) --fundcode Counter Declare @counterFundId int = 0 select @counterFundId = count(fundcode) from @fundcodestable declare @fundC varchar(300) while @counterFundId <>0 and @NextDate<=@EndDate begin set @fundC = (select top 1 fundcode from @fundcodestable) Set @Val = 0 if @Zero = 0 begin if @LongShortAll = 0 begin exec GetFundValue @fundC, @NextDate, @Val output end else begin if @LongShortAll = 1 begin if @PhysEff = 0 begin exec GetFundValueLongOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueLongOnly @fundC, @NextDate, @Val output end end else begin if @PhysEff = 0 begin exec GetFundValueShortOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueShortOnly @fundC, @NextDate, @Val output end end end end else begin If @LongShortAll = 0 begin exec GetFundValue\_ZeroFutures @fundC, @NextDate, @Val output
-
Hi I'm running the below query, I want to get records for multiple fundCodes in this case Bateleur and Tower Fund.I'm only getting records for Bateleur only from 2016-04-20 to 2016-04-29. Thank you
Declare @FundCodes VarChar(Max)='Bateleur|Tower Fund',--Tower Fund
@StartDate DateTime='2016/04/20',
@EndDate DateTime='2016/04/29',
@Zero integer=1,
@LongShortAll integer = 0, --0 for all, 1 for long value, 2 for short value
@PhysEff integer = 0 --0 for physical, 1 for Effective--check the fulldate select fulldate into #TableDates from AssetData.dbo.Calendar cal where cal.FullDate between @StartDate and @EndDate and IsWeekDay = 1 and IsHoliday = 0 -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @NextDate DateTime set @NextDate = @StartDate declare @TempValues table(FundCode varchar(200),EffectiveDate DateTime, Value Float) declare @fundcodestable table (ID int, fundcode varchar(300)) declare @Val float --Date Counter declare @DateCounter int = 0 select @DateCounter = count(Fulldate) from #TableDates declare @Date date while @DateCounter <> 0 begin set @Date = (select top 1 fulldate from #TableDates order by 1) --fundcode insert into @fundcodestable select pn, s from StagedFundReportingData..FnxSplit('|', @fundcodes) --fundcode Counter Declare @counterFundId int = 0 select @counterFundId = count(fundcode) from @fundcodestable declare @fundC varchar(300) while @counterFundId <>0 and @NextDate<=@EndDate begin set @fundC = (select top 1 fundcode from @fundcodestable) Set @Val = 0 if @Zero = 0 begin if @LongShortAll = 0 begin exec GetFundValue @fundC, @NextDate, @Val output end else begin if @LongShortAll = 1 begin if @PhysEff = 0 begin exec GetFundValueLongOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueLongOnly @fundC, @NextDate, @Val output end end else begin if @PhysEff = 0 begin exec GetFundValueShortOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueShortOnly @fundC, @NextDate, @Val output end end end end else begin If @LongShortAll = 0 begin exec GetFundValue\_ZeroFutures @fundC, @NextDate, @Val output
And what is your question?
-
Hi I'm running the below query, I want to get records for multiple fundCodes in this case Bateleur and Tower Fund.I'm only getting records for Bateleur only from 2016-04-20 to 2016-04-29. Thank you
Declare @FundCodes VarChar(Max)='Bateleur|Tower Fund',--Tower Fund
@StartDate DateTime='2016/04/20',
@EndDate DateTime='2016/04/29',
@Zero integer=1,
@LongShortAll integer = 0, --0 for all, 1 for long value, 2 for short value
@PhysEff integer = 0 --0 for physical, 1 for Effective--check the fulldate select fulldate into #TableDates from AssetData.dbo.Calendar cal where cal.FullDate between @StartDate and @EndDate and IsWeekDay = 1 and IsHoliday = 0 -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @NextDate DateTime set @NextDate = @StartDate declare @TempValues table(FundCode varchar(200),EffectiveDate DateTime, Value Float) declare @fundcodestable table (ID int, fundcode varchar(300)) declare @Val float --Date Counter declare @DateCounter int = 0 select @DateCounter = count(Fulldate) from #TableDates declare @Date date while @DateCounter <> 0 begin set @Date = (select top 1 fulldate from #TableDates order by 1) --fundcode insert into @fundcodestable select pn, s from StagedFundReportingData..FnxSplit('|', @fundcodes) --fundcode Counter Declare @counterFundId int = 0 select @counterFundId = count(fundcode) from @fundcodestable declare @fundC varchar(300) while @counterFundId <>0 and @NextDate<=@EndDate begin set @fundC = (select top 1 fundcode from @fundcodestable) Set @Val = 0 if @Zero = 0 begin if @LongShortAll = 0 begin exec GetFundValue @fundC, @NextDate, @Val output end else begin if @LongShortAll = 1 begin if @PhysEff = 0 begin exec GetFundValueLongOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueLongOnly @fundC, @NextDate, @Val output end end else begin if @PhysEff = 0 begin exec GetFundValueShortOnly @fundC, @NextDate, @Val output end else begin exec GetFundUnderlyingEffectiveValueShortOnly @fundC, @NextDate, @Val output end end end end else begin If @LongShortAll = 0 begin exec GetFundValue\_ZeroFutures @fundC, @NextDate, @Val output
-
Just a suggestion. Print the results from the following
insert into @fundcodestable
select pn, s
from StagedFundReportingData..FnxSplit('|', @fundcodes)