Click here to Skip to main content
15,886,788 members
Home / Discussions / Database
   

Database

 
AnswerRe: Issue on communicating data from two difference system with different names Pin
Mycroft Holmes19-Sep-16 20:17
professionalMycroft Holmes19-Sep-16 20:17 
AnswerRe: Issue on communicating data from two difference system with different names Pin
Jörgen Andersson19-Sep-16 20:17
professionalJörgen Andersson19-Sep-16 20:17 
QuestionMariaDB und Updates with select same table Pin
RMolino17-Sep-16 8:33
RMolino17-Sep-16 8:33 
AnswerRe: MariaDB und Updates with select same table Pin
Mycroft Holmes17-Sep-16 11:22
professionalMycroft Holmes17-Sep-16 11:22 
GeneralRe: MariaDB und Updates with select same table Pin
RMolino18-Sep-16 0:42
RMolino18-Sep-16 0:42 
QuestionMajor differences between sql server express and sql server localdb Pin
Tridip Bhattacharjee5-Sep-16 23:20
professionalTridip Bhattacharjee5-Sep-16 23:20 
AnswerRe: Major differences between sql server express and sql server localdb Pin
Eddy Vluggen6-Sep-16 0:29
professionalEddy Vluggen6-Sep-16 0:29 
QuestionSQL While loop Pin
Mphirana31-Aug-16 4:40
Mphirana31-Aug-16 4:40 
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

SQL
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
						end else begin
							if @LongShortAll = 1 begin
								if @PhysEff = 0 begin
									exec GetFundValueLongOnly_ZeroFutures @fundC, @NextDate, @Val output
								end else begin
									exec GetFundUnderlyingEffectiveValueLongOnly_ZeroFutures @fundC, @NextDate, @Val output
								end
							end else begin
								if @PhysEff = 0 begin
									exec GetFundValueShortOnly_ZeroFutures @fundC, @NextDate, @Val output
								end else begin
									exec GetFundUnderlyingEffectiveValueShortOnly_ZeroFutures @fundC, @NextDate, @Val output
								end
							end
						end
					end
					Set @Val = isnull(@Val,0)

					if @Val <> 0
					begin
						insert into @TempValues (FundCode,EffectiveDate, Value) Values (@fundC,@NextDate, @Val)
					end

					if datepart(dw,@NextDate) = 7
					begin
						Set @NextDate = DATEADD(Day,2,@NextDate)
					end
					else
					begin
						if datepart(dw,@NextDate) = 6
						begin
							Set @NextDate = DATEADD(Day,3,@NextDate)
						end
						else
						begin
							Set @NextDate = DATEADD(Day,1,@NextDate)
						end 
					end
				  end
			    delete #TableDates where FullDate = @NextDate
		      select @DateCounter = @DateCounter-1
			 --delete @fundcodestable where fundcode = @fundC
		  --     set @counterFundId = @counterFundId - 1  	
		 end
			

		Select * from @TempValues order by FundCode
		drop table #TableDates

AnswerRe: SQL While loop Pin
Victor Nijegorodov31-Aug-16 21:57
Victor Nijegorodov31-Aug-16 21:57 
AnswerRe: SQL While loop Pin
jschell1-Sep-16 7:10
jschell1-Sep-16 7:10 
GeneralRe: SQL While loop Pin
Mphirana1-Sep-16 9:40
Mphirana1-Sep-16 9:40 
QuestionExposing API VS Stored Procedure Pin
Java Lead31-Aug-16 4:29
Java Lead31-Aug-16 4:29 
AnswerRe: Exposing API VS Stored Procedure Pin
Richard MacCutchan31-Aug-16 4:46
mveRichard MacCutchan31-Aug-16 4:46 
Question.mdf file not updated? Pin
kmllev26-Aug-16 16:59
kmllev26-Aug-16 16:59 
GeneralRe: .mdf file not updated? Pin
Richard MacCutchan26-Aug-16 21:07
mveRichard MacCutchan26-Aug-16 21:07 
AnswerRe: .mdf file not updated? Pin
Eddy Vluggen29-Aug-16 4:06
professionalEddy Vluggen29-Aug-16 4:06 
GeneralRe: .mdf file not updated? Pin
kmllev29-Aug-16 5:16
kmllev29-Aug-16 5:16 
QuestionHow to speedup the execution of a query in Sql Server? Pin
Abhijit Mindcraft22-Aug-16 22:52
Abhijit Mindcraft22-Aug-16 22:52 
AnswerRe: How to speedup the execution of a query in Sql Server? Pin
Mycroft Holmes22-Aug-16 23:11
professionalMycroft Holmes22-Aug-16 23:11 
AnswerRe: How to speedup the execution of a query in Sql Server? Pin
David Mujica23-Aug-16 5:35
David Mujica23-Aug-16 5:35 
GeneralRe: How to speedup the execution of a query in Sql Server? Pin
Abhijit Mindcraft23-Aug-16 19:58
Abhijit Mindcraft23-Aug-16 19:58 
GeneralRe: How to speedup the execution of a query in Sql Server? Pin
Mycroft Holmes23-Aug-16 20:20
professionalMycroft Holmes23-Aug-16 20:20 
AnswerRe: How to speedup the execution of a query in Sql Server? Pin
Eddy Vluggen24-Aug-16 4:09
professionalEddy Vluggen24-Aug-16 4:09 
GeneralRe: How to speedup the execution of a query in Sql Server? Pin
Abhijit Mindcraft24-Aug-16 18:57
Abhijit Mindcraft24-Aug-16 18:57 
QuestionBasic Join Not Working (Copy From LAMP Forum) Pin
Django_Untaken19-Aug-16 2:18
Django_Untaken19-Aug-16 2:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.