Completed

Improve a MS-SQL Query with a Loop

We need a improvement of a MS-SQL Query - At the moment the query looks like this:

declare @InventurDatum AS DATETIME;

declare @InventurDatum2 AS DATETIME;

SET @InventurDatum = CONVERT(datetime, '01/03/2018 00:00:00', 103);

SET @InventurDatum2 = CONVERT(datetime, '28/03/2018 23:59:59', 103);

SELECT

[url removed, login to view],

[url removed, login to view],

[url removed, login to view],

(

select sum([url removed, login to view]) from tbestellpos asdf

LEFT JOIN tBestellung bes ON asdf.tBestellung_kBestellung = [url removed, login to view]

WHERE asdf.tArtikel_kArtikel = [url removed, login to view] AND [url removed, login to view] > @InventurDatum and [url removed, login to view] < @InventurDatum2

)

as Verkauf,

CAST((select A.fLagerbestand-coalesce(sum([url removed, login to view]),0 ) FROM [eazybusiness].[dbo].[tArtikelHistory] AS D WHERE A.kArtikel=[url removed, login to view] and [url removed, login to view] != 1AND [url removed, login to view] > @InventurDatum) AS int) as 'Anfang',

CAST((select A.fLagerbestand-coalesce(sum([url removed, login to view]),0 ) FROM [eazybusiness].[dbo].[tArtikelHistory] AS D WHERE A.kArtikel=[url removed, login to view] and [url removed, login to view] != 1AND [url removed, login to view] > @InventurDatum2) AS int) as 'Ende'

FROM [eazybusiness].[dbo].[tlagerbestand] AS A

LEFT JOIN tArtikelBeschreibung cd ON [url removed, login to view] = [url removed, login to view]

LEFT JOIN [eazybusiness].[dbo].[tArtikel] AS B ON [url removed, login to view] = [url removed, login to view]

WHERE

[url removed, login to view] != 1 AND [url removed, login to view] = 1 and [url removed, login to view] = 1

order by [url removed, login to view] asc

#######

What we need is kind of loop within this query through each day between @ InventurDatum and @ InventurDatum2 which returns the amount for each day in a single row with the day as the rows headline.

Skills: Microsoft SQL Server, SQL

See more: avoid using sql queries inside a loop, how to avoid nested loops in sql server, sql nested loop example, how to optimize inner join query in sql server, how to improve while loop performance in sql server, postgres nested loop slow, postgres avoid nested loop, nested loop join in sql server example, SQL Query, MS SQL development, SQL Query, MS SQL Administartion, sql query loop, ms sql query mysql convert, improve sql query time oscommerce, convert ms sql query mysql, design sql query forum tree

About the Employer:
( 6 reviews ) Ettlingen, Germany

Project ID: #16507041

Awarded to:

logos104

Hi. I'm professional software developer with more than 15 years of experience. I'm able to improve the query.

€40 EUR in 1 day
(3 Reviews)
3.4

14 freelancers are bidding on average €23 for this job

codetod

Hi I am a database expert with 15 years experience in handling MS SQL databases. I have worked as DBA for large ERP databases and use to write and do performance tuning for SQL queries, procedures and triggers. More

€25 EUR in 1 day
(48 Reviews)
5.8
logiclast

Hi, I am having expert level experience in SQL Server last 7 years. I would like to work in this project. I will provide you quality output withing a time frame we define. Please let us know your convenient time to More

€39 EUR in 10 days
(1 Review)
3.7
FerriSoft1

Hi, would you mind send me a .bak witha subset of the data, I know how to do CURSORs loops in SQL Server with FETCH operations, don't know if that would be the best ways to achieve results here, but I have to see a su More

€30 EUR in 1 day
(4 Reviews)
2.5
VnNorthStar

Hi I'm ready for this project. I'm expert in MS SQL. Please give me an opportunity. I will do it perfectly.

€15 EUR in 1 day
(2 Reviews)
1.4
sreenivas2903

its pleasure to work the optimizations part and automation parts , if you would like to believe I could give you the best , please let me know . waiting for response

€24 EUR in 0 days
(2 Reviews)
1.1
vw7313987vw

Hi, I'm expert in software building domain, having good exposure to backend & frontend programming. I feel I can complete your job. Please consider my profile. Thanks Regards, Gagan

€23 EUR in 1 day
(0 Reviews)
0.0
kartiksharma4949

A proposal has not yet been provided

€12 EUR in 2 days
(0 Reviews)
0.0
€23 EUR in 1 day
(0 Reviews)
0.0
sitaparaca

A proposal has not yet been provided

€24 EUR in 3 days
(0 Reviews)
0.0
€14 EUR in 1 day
(0 Reviews)
0.0
csen516

Hello dear Hiring manager I have read your job post & being an expert Web developer, I offer myself for the job. I am having extensive knowledge and 5+ years of experience in PHP & WordPress website development u More

€23 EUR in 1 day
(0 Reviews)
0.0
€23 EUR in 1 day
(0 Reviews)
0.0
simrankaurc

Hello, I am very interested in the project and you would like to apply to it. I'm a web developer with 7 years experience in PHP, MYSQL, CSS3, HTML5 and deep knowledge Wordpress, WP pluggin, development issues More

€8 EUR in 1 day
(1 Review)
0.0