|
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',
@StartDate DateTime='2016/04/20',
@EndDate DateTime='2016/04/29',
@Zero integer=1,
@LongShortAll integer = 0,
@PhysEff integer = 0
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;
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
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)
insert into @fundcodestable
select pn, s
from StagedFundReportingData..FnxSplit('|', @fundcodes)
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
end
Select * from @TempValues order by FundCode
drop table #TableDates
|
|
|
|
|
And what is your question?
|
|
|
|
|
Just a suggestion. Print the results from the following
insert into @fundcodestable
select pn, s
from StagedFundReportingData..FnxSplit('|', @fundcodes)
|
|
|
|
|
Thank you Jschell, I managed to fix the problem.
|
|
|
|
|
Hi,
I have a Oracle DB in which all the information is stored and this information is been consumed by different teams and below is the two options i have to decide on :
1. Write a Stored procedure and give the stored procedure to the respective teams and they can call the stored procedure.
2. Write a stored procedure wrap it as an API and expose the API, different team will call the API exposed and API will in turn hit the SP and return the response to the team.
Like to know what is the PRON and CRONS with these options and what is the best possible solution to go with.
Thanks
|
|
|
|
|
|
We are working on separate computers in different locations so we are not connected to a network.
We are using SQL Server 2016 Express to develop a C# application in Visual Studio (college project).
My group mate sent me the (.bak) and (.mdf) files of the database he was working on so I can view it and make the necessary updates. I saw the data in the files after restoring and attaching them respectively. Some columns that were in (.bak)file were not in the (.mdf) file, and I need the (.mdf) file to be updated/contain the same data with the .bak file so I can add a datasource to the application for easy retrieval of data.
What could possibly have been the problem?
|
|
|
|
|
kmllev wrote: What could possibly have been the problem? Could have been any one of a million things. Without much more information it is impossible to guess.
|
|
|
|
|
kmllev wrote: What could possibly have been the problem? Are you sure the columns are in the .bak file?
Restore it to a new database, and make sure you have rights to write to the database; post any errors you see here
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
How to speedup the execution of a query in Sql Server?
|
|
|
|
|
In SSMS under tool the first entry is SQL Server Profiler - use that as your first step.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You need to present a bit more detail so that some suggestions can be given.
Generally, are you linking tables together ? How many? How many rows are in each table?
How many rows are being returned in your query?
With the SQL profiler you will be able to tell whether the server is scanning the table or seeking data via an index.
Your question is too vague to get a valuable answer.
|
|
|
|
|
Hi David Mujica,
Thanks for your reply,but I need just rough idea or tips.
|
|
|
|
|
My response was a tip, without more information we can't really be more specific. Statements like check you indexes (profiler helps) and check your syntax are going to be basically all we can do.
Tuning a DB and queries is almost an art so you need to give us some subject matter. What you have given us is like asking why your painting is rubbish!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
After checking your keys and indexes, you could try to omit as much functions in the query as possible, limit the case-when switches and remove any unused tables and/or columns.
MSDN also has a few pages on the subject
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi Eddy Vluggen,
It helps me a lot. 
|
|
|
|
|
Hello there. I am trying to get data from 3 different tables based on simple join. One of the tables can have multiple values against one primary key. Here are the table designs
Table 1 - EmployeeDetails
EmployeeId INT, FirstName VARCHAR, SurName VARCHAR, SexId INT
Table 2 - EmployeeSex
SexId INT, Sex VARCHAR
Table 3 - EmployeeContacts
EmployeeId INT, Contact VARCHAR
I am using following query
SELECT ED.EmployeeId, ED.FirstName, ED.SurName, GROUP_CONCAT(EC.Contact)
FROM EmployeeDetails ED, EmployeeSex ES, EmployeeContacts EC
WHERE ED.SexId = ES.SexId AND ED.EmployeeId = EC.EmployeeId AND ED.EmployeeId = 'emp_password';
Now this query works fine if we have at least one contact number. But if there are not contacts, then this results in empty set. What is wrong with this query ? How can I improve so that it works in all scenarios (regardless of number of contacts in EmployeeContacts table). Thanks for any input.
|
|
|
|
|
Use joins, not a where condition
SELECT ED.EmployeeId, ED.FirstName, ED.SurName, GROUP_CONCAT(EC.Contact)
FROM EmployeeDetails ED
INNER JOIN EmployeeSex ES on ED.SexId = ES.SexId
LEFT JOIN EmployeeContacts EC on ED.EmployeeId = EC.EmployeeId
WHERE ED.EmployeeId = 'emp_password';
If there are instance where an employee does not have an assigned sex, change the INNER JOIN to a LEFT JOIN
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Hi.
I have to choose between MySQL and PostgreSQL. I like use MS SQL, but it expensive for the customer.
Database have about 100 tables with max. 200 thousands rows.
Front application is .NET (winform) ,dataset or entity framework.
It's critical application, reliability is required.
Please advice me.
Karol
|
|
|
|
|
Member 9076609 wrote: It's critical application, reliability is required. Sounds like Oracle or SQL Server are the only two choices to consider.
|
|
|
|
|
If it isn't too big, consider SQLServer Express.
You may need to get creative in access, but that can be done.
Don't forget to build some database maintenance, backup, etc.
|
|
|
|
|
Member 9076609 wrote: Please advice me. Leave the choice to the customer.
Program against the IDb-interfaces and use ANSI-92 SQL
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, there's a lot of comparisons out there to read if you want to.
But the tl;dr is:
Performance and scalability -> MySql
Reliability, data integrity and standard compliance -> PostGreSQL.
While MySQL has gotten a lot better with the last versions it's still lacking a lot of functionality. And while it also can be (a lot) faster, it's only in certain scenarios.
If you do a lot of paging, PostGres is the one outperforming everyone else.
My personal choice would be PostGres, but mostly because it's more familiar as I have mostly used Oracle and SQLServer.
|
|
|
|
|
|