Re-Running Query

Jun 20, 2007

Presumably, an RDL data set is only queried once before generating a report. And presumably, this is true even if the data set feeds a list control. However, I'd like to know if I can cause a data set to be queried repeatedly from a list control. I need to do this, because the data set contains aggregate functions that would be impacted by each "pass" the list control would make.



Is it possible to make a data set queried repeatedly in this fashion?

View 1 Replies


ADVERTISEMENT

How To Kill A Long Running Query Running On A Background Thread.

Sep 1, 2006


If I start a long running query running on a background thread is there a way to abort the query so that it does not continue running on SQL server?

The query would be running on SQL Server 2005 from a Windows form application using the Background worker component. So the query would have been started from the background workers DoWork event using ado.net. If the user clicks an abort button in the UI I would want the query to die so that it does not continue to use sql server resources.

Is there a way to do this?

Thanks


View 1 Replies View Related

Re-display Result Set Without Re-running Query In Query Analyzer?

Apr 9, 2006

I hope I am not asking about something that has been done before, but Ihave searched and cannot find an answer. What I am trying to do is torun a query, and then perform some logic on the rowcount and thenpossibly display the result of the query. I know it can be done withADO, but I need to do it in Query Analyzer. The query looks like this:select Varfrom DBwhere SomeCriteriaif @@Rowcount = 0select 'n/a'else if @@Rowcount = 1select -- this is the part where I need to redisplay the resultfrom the above queryelse if @@Rowcount > 1-- do something elseThe reason that I want to do it without re-running the query is that Iwant to minimize impact on the DB, and the reason that I can't useanother program is that I do not have a develpment environment where Ineed to run the queries. I would select the data into a temp table, butagain, I am concerned about impacting the DB. Any suggestions would begreatly appreciated. I am really hoping there is something as simple as@@resultset, or something to that effect.

View 6 Replies View Related

Very Slow Running Update Query Query

Nov 19, 2004

I have an update query running which to just now has been running for 22 hours running on two tables 1 a lookuptable that has just been created within the batch the other a denormalised table for doing data analysis on

the query thats causing teh problem is


--//////////////////////////////////// this is the one thats running


Print 'Update Provider 04-05 EmAdmsCount12mths : ' + CAST(GETDATE() AS varchar)
GO
Update Provider_APC_2004_05
set EmAdmsCount12mths =
(Select COUNT(*)-1
from Combined_Admissions
where ((Combined_Admissions.NHSNumber = Provider_APC_2004_05.NHSNumber) or
(Combined_Admissions.PASNUMBER = Provider_APC_2004_05.PDDISTNO)) and
(Combined_Admissions.AdmDate BETWEEN DateAdd(yyyy,-1,Provider_APC_2004_05.AdmDate) AND Provider_APC_2004_05.AdmDate) AND
Combined_Admissions.AdmMethod like 'Emergency%')-- and
-- CA.NHSorPrivate = 'NHS'))
FROM Provider_APC_2004_05, Combined_Admissions


any help in improving speed would be most welcome as there are 3 more of these updates to run right after this one and the analysis tables are almost double the size of this one

Dave

View 6 Replies View Related

Running Query After Query And Input Variables

Jul 8, 2013

I have 2 requests for desperate Hélio..

1) is there any way to run a query over a query without having to create a table with the results of the first query? (would drop table work? If so, how?

2) how can i define input variables the same way i do in excel? I am trying to run a couple of simulations based on 2 core inputs (in excel i would just do a data table)

View 7 Replies View Related

Help Running A Query Please

Apr 10, 2008

Hi guys. I'm looking for help to run a query that should come out looking like this


unit reports_to

Development Dept Representative Div
Systems Group Development Dept
Design Section Systems Group
Production Spec Section Systems Group
Proposal Section Systems Group

This is the table i have to work from

UNITNOORGNAME PARENTBUDGET
2000Representative Div1000459000.0000
2100Development Dept2000391000.0000
2110Systems Group 2100332000.0000
2111Proposal Section211087000.0000
2112Design Section 2110132000.0000
2115Production Spec Sect211068000.0000

I can't see any way of doing this query though I know the PARENT is the reports_to column and that the UNITNO is the Department but can't find any way to run the query. Hoping you guys can help

Thanks

View 10 Replies View Related

Long Running Query - Only From .NET

Aug 22, 2007

I have a pretty complex query that aggregates lots of data and inserts multiple rows of that data into a reporting table.  When I call this SPROC from SQL Server Management Studio, it executes in under 3 seconds.  When I try to execute the same SPROC using .NET's SqlCommand object the query runs indefinitely until the CommandTimeout is reached. Why would this SPROC behave differently with the same inputs, but being called from .NET? Thanks for your help! 

View 3 Replies View Related

Why Is The Query Running For So Long?

Feb 7, 2003

When I execute the following stored procedure it runs for about a minute.

CREATE PROCEDURE EquipmentListByProduct
(
@iProdTypeId int
)
AS

SET NOCOUNT ON
DECLARE@iError int, @iRows int

SELECT pn.prodTypeId, pn.prodId, pn.prodName
FROM prodNames pn
WHERE pn.prodTypeId = @iProdTypeId

SELECT@iError = @@ERROR, @iRows = @@ROWCOUNT
IF ( @iError <> 0 )
BEGIN
RETURN@iError
END

IF ( @iRows = 0 )
BEGIN
RETURN-1
END

RETURN@iError
GO


The table only has 22 records.
Do I need to index the table? If so how do I do this?

View 4 Replies View Related

SQL Query Running Much Slower Than EM

Jun 12, 2002

Ok,
here's a funky one That I can't find an expanation for. If I go into EM and choose a table from a database and return all rows, I get immediate results and can start browsing records. If I go into query analyzer and do a select * on the same table, it takes up to 20-25 minutes to return the result set. This used to only take like 5 mins. What gives? Anyone seen this before?

View 1 Replies View Related

Running Query From Two Sql Sever

Aug 24, 2004

Hi Everybody,

I have two SQL server one in the office and other on remote location. I have some data on SQL in the office and some data on remote location and need to query the data.

how can I do that ?

Thanks for your help in advacne

View 1 Replies View Related

Error While Running Query

Mar 2, 2004

Hi,

SQL Server 7
When i ran a query in query analyzer i am getting the below error.
once i closed and opened the query analyzer and ran the same query it worked fine.

pls the error which i got in first time.

Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]Protocol error in TDS stream
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]Unknown token received from SQL Server
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large
[Microsoft][ODBC SQL Server Driver]TDS buffer length too large

Pls help me in this

TIA
Adil

View 5 Replies View Related

Query Running On A Schedule

Apr 29, 2008

Can someone please let me know how i can set up a query to execute once a week lets say on tuesdays at 6 am...
i do not see how i can set this. can anyone help me please

View 1 Replies View Related

Query Analyser Not Running

Mar 18, 2006

Hi


I am install sql 2000, Server is running properly
but query analyer is not working...


Thanks


ASM

View 9 Replies View Related

Running Query On All Databases Within An SQL

Oct 3, 2007

Hi,

I'm running SQL 2000 SP4.

On this server I have a few databases. I need to run the below query against each database. Since the server has approx 50 databases this will take time.

Is there any way for me to modify this so as it will automatically
run against each database one at a time and then create a single output file with all the results.

I do not want it to run against all of the databases at the same time as it will kill my server so it must run and gather results on each database at a time.


QUERY to be run

SELECT RelativeFileName

FROM Collection, Saveset

WHERE Collection.CollectionIdentity = Saveset.CollectionIdentity

View 11 Replies View Related

Running A Query On Two Databases

Mar 31, 2008

Hello all,
Can anyone please tell me what query to use for joining two tables in two databases together?

Basically, we have two databases called 'system' and 'site' respectively. The 'system' database has a table called 'users' and each user has a unique id which is also linked to the tables in the 'site' database.

The only problem i have got is, I want to be able to get the actual user names not the unique id and the only way to get this from my SQL statement is to be able to link the uniqueid for each user in the 'site' database to their corresponding uniqueid in the 'system' database.

Please, how can I do this?

View 14 Replies View Related

Running A DLL In The Query Analyzer

Nov 23, 2007

Hi,I have a DLL that I want to run from the Query Analyzer. I tried thefollowing:USE master;EXEC sp_addextendedproc BLAH, '\Other-ServerPathToBlahBlah.dll'and I get the error:ODBC: Msg 0, Level 16, State 1Cannot load the DLL \Other-ServerPathToBlahBlah.dll, or one ofthe DLLs it references. Reason: 126(The specified module could not befound.).The DLL was written in Cobol. The "Other-Server" in the Path above isthe server that Cobol (and the DLL) is located on.I looked at the dependencies for the DLL and it includes (notsurprisingly) Cobol Dll's. It should find those on the other server.What can I do?Thanks!

View 5 Replies View Related

Error While Running A Query

Dec 12, 2007

I have recieved the following error message while running a query on SQL2k5 on a Windows 2003 64-bit EE server


"The operating system returned error 1450(error not found) to SQL Server during a write at offset 0x00001c32062000 "

I will be grateful if anyone can point me in the right direction on what this can be.

Thanks

View 3 Replies View Related

Long Running Query

Jun 2, 2006

Hi,

I'm trying to optimize a long running (several hours) query. This query is a cross join on two tables. Table 1 has 3 fields - ROWID, LAt and Long. Table 2 has Name, Addr1,Addr2,City,State,Zip,Lat,Long.

Both tables has LatRad - Lat in radians, LonRad- Lon in Radians. Sin and Cos values of Lat and Lon are calulated and stored to be used in the distance formula.

What I'm trying to do here is find the nearest dealer (Table 2) for each of Table 1 rows. The Select statement takes a long time to execute as there are about 19 million recs on table 1 and 1250 rows in table 2. I ran into Log issues- filling the transaction log, so I'm currently using table variables and split up the process into 100000 recs at a time. I cross join and calculate the distance (@DistValues) and then find the minimum distance (tablevar2) for each rowid and then the result is inserted into another Table (ResultTable).

My Code looks like this:

Declare @DistValues table (DataSeqno varchar(10),Lat2 numeric(20,6),Lon2 numeric(20,6),StoreNo varchar(60), Lat1 numeric(20,6),Long1 numeric(20,6),Distance numeric(20,15))

Declare @MinDistance table (DataSeqno varchar(10) primary key,distance numeric(20,15))

Insert into @DistValues

Select DataSeqno,T.Lat Lat2,T.Lon Lon2,S.StoreNo,S.Lat Lat1,S.Long Long1,

distance=3963.1*Case when cast(S.SinLat * T.SinLat + S.CosLat * T.cosLat * cos(T.Lonrad - s.Lonrad) as numeric(20,15)) not between -1.0 and 1.0 then 0.0 else acos(cast(S.SinLat * T.SinLat + S.CosLat * T.cosLat * cos(T.Lonrad - s.Lonrad) as numeric(20,15))) end

from dbo.TopNForProcess T , dbo.Table2 S where Isnull(T.Lat,0) <> 0 and Isnull(T.Lon,0)<> 0

Insert into @MinDistance

Select DataSeqno,Min(distance) From @DistValues Group by DataSeqno

Insert into ResultTable (DataSeqno,Lat2,Lon2,StoreNo,LAt1,Long1,distance)

Select D.DataSeqno, D.Lat2, D.Lon2, D.StoreNo, D.LAt1, D.Long1, M.distance from @DistValues D Inner Join @MinDistance M on D.DataSeqno = M.DataSeqno and D.Distance = M.Distance

I created a View called TopNForProcess which looks like this. This cut down the processing time compared to when I had this as the Subquery.

SELECT TOP (100000) DataSeqno, lat, Lon, LatRad, LonRad, SinLat, cosLat, SinLon, CosLon FROM Table1 WHERE (DataSeqno NOT IN (SELECT DataSeqno FROM dbo.ResultTable)) AND (ISNULL(lat, 0) <> 0) AND (ISNULL(Lon, 0) <> 0)

I have indexes on table table1 - Rowid and another one with Lat and lon. Table2 - Lat and Long.

Is there any way this can be optimized/improved? This is already in a stored procedure.

Thanks in advance.

View 7 Replies View Related

Running Sums Query

Oct 18, 2007

I am trying to write a query that gets daily sales for each of our stores plus WTD and MTD totals

columns would be

Store date daily_total wtd_total mtd_total

the query need to produce a row per store per day and have the wtd sum reset for each week so that it
sums up sales day by day for that week

Is there a good way to do this?

View 3 Replies View Related

Query Running Slow

Aug 24, 2007

hi

if suppose one query is running slow than what steps we can follow to optimize it...

this question is asked me in interview.

thanx

View 3 Replies View Related

Running Query Problem

Sep 20, 2007



Hi,

I have a query that has cursor loop.
in each loop there is many sql update commands.
it runs good in sql2000.

now when i run it in sql2005 it continue for a long time and not finish.
when i run each command that within the loop alone it runs good, but when i run it all together its not finish running.
i dont get any error. i think maybe the table that i'm bulk updating is in some lock and this is why it stuck in the running and not finish.

Is there a way to make sure that there is no lock on a table before i update it during my running.

Thanks.

View 3 Replies View Related

Automatically Running Sql Query Every Week

Aug 14, 2007

I have a simple query (a select statement which retrieves results from 2 tables via join).  I run this query every week and just copy the results from Management Studio (Ctrl-A) and then open Microsoft Excel and just paste it there.
Is there a way I can automatically run this every week and generate the Excel from the results?  If so what steps I have to do?
I use SQL Server 2005 Express Edition.

View 5 Replies View Related

Running An Insert Query Using A Button

Jan 22, 2008

Hey, I have created a webpage using visual web developer and i want to use it as a frontend to a database. I want to be able to insert a new line into a table using a drop down menus then a 'submit' button. How do I get the submit button to run the following sql query?
insert into master_training_table (user_rec_no,Course_rec_no,Planned_date,Inserted_date) select @user_rec_no,id_training,convert(smalldatetime,convert(varchar(12),getdate()))+planned_date,getdate() from tbl_training tb join tbl_user_groups tg on tb.groups_id = tg.groups_id where tg.groups_id = @groups_id
thanks for your help
 

View 3 Replies View Related

Running Query For Linked Server

May 23, 2001

I have created a linked server using an ODBC connection to an Access database. The command I used for this was:

EXEC sp_addlinkedserver
@server = 'Testaccess',
@srvproduct = '',
@provider = 'MSDASQL',
@datasrc = 'test'
GO

where 'Testaccess' is the name of the linked server and 'test' is the name of the ODBC connection. [The ODBC connection stores the name of the Access datbase.]

I can run sp_tables_ex and view the table_schem, table_cat etc etc

BUT when I try to run a query on the linked server, I get the following message:

"7312 - Invalid use of schema and/or catalog for OLE DB provider '%ls'. A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog and/or schema."

I am attempting/using the following command specifying the linked server name.database name.owner.table name in the FROM clause:

select a.*
from testaccess.testdb.dbo.temptable a

Any ideas what I am doing wrong??

thanks
Jan

View 1 Replies View Related

How To Cancel A Sql Query Running From Front End

May 31, 2001

how do i cancel and sql query running through stored procedure
which is called from the front end.

please help me

View 1 Replies View Related

Optimizin Query Which Is Running For Hours

Feb 23, 2006

Hi Can somebody suggest optimization on this query.
ITs running for hours,I have checked on mutiple Servers but dont know where the problem is.It starts when i add the not exists piece if the query.
Pls help

SELECT distinct
isnull(P.id,'') PersonID
, s.status
, isnull(replace(Ltrim(Rtrim(P.Firstname)),',',''),' ') FirstName
, isnull(replace(Ltrim(Rtrim(P.MiddleName)),',',''), '') MiddleName
, isnull(replace(Ltrim(Rtrim(P.lastname)),',',''),'' ) LastName
, isnull(replace(Ltrim(Rtrim(P.Suffix)),',',''),'') Suffix
, isnull(replace(Ltrim(Rtrim(p.company)),',',''),'') Company
, isnull(replace(Ltrim(Rtrim(PA.AddressLine1)),',',' '),'') AddressLine1
, isnull(replace(Ltrim(Rtrim(PA.AddressLine2)),',',' '),'') AddressLine2
, isnull(replace(Ltrim(Rtrim(PA.City)),',',''),'') City
, State = isnull(replace(Ltrim(Rtrim(PA.State)),',',''),'')
, ZipCode = ISNULL(CASEWHEN LEN((LTRIM(RTRIM(PA.Zipcode)))) = 3 THEN ('00' + (PA.Zipcode))
WHEN LEN((LTRIM(RTRIM(PA.Zipcode)))) = 4 THEN ('0' + (PA.Zipcode))
WHEN SUBSTRING(LTRIM(RTRIM(PA.Zipcode)),6,1) = '-' THEN ISNULL(PA.Zipcode,'')
WHEN SUBSTRING(PA.Zipcode,6,1) = ' ' THEN ISNULL(PA.Zipcode,'')
ELSE substring(PA.Zipcode,1,5)+'-'+ substring(PA.Zipcode,6,4)
END ,'')
, b.code
, CommitteeTermID = ''
, RevenueCategoryid = ''
FROM vwpersons p with (nolock)
join vwsubscriptions s on p.id = s.recipientid
join vwcompanies c WITH (NOLOCK) on c.id = p.companyid
join vwbusinesscodes b WITH (NOLOCK) on b.id = c.primarybusinesscode
join vwRevenueCategorys rc WITH (NOLOCK)on rc.id = c.RevenueCategoryid
join vwPersonPrefAddr pa WITH (NOLOCK) on p.id = pa.id
WHERE NOT EXISTS (SELECT s1.recipientid FROM vwsubscriptions S1 WHERE S1.SHIPTOID =S.SHIPTOID
AND S.PRODUCTID = S1.PRODUCTID AND S1.STATUSID IN (1,2,3,11,12))
and p.id in (select recordid from vwTopicCodeLinks tcl
Where tcl.entityid = 457
And tcl.topiccodeid = 332
And tcl.value = 'Yes')
and ((p.PreferredAddress = 'Business Address' and p.BadBusinessAddress = 0)
or (p.PreferredAddress = 'PO Box Address' and p.BadPOBoxAddress = 0)
or(p.PreferredAddress = 'Home Address' and p.BadHomeAddress = 0))
and b.code in ( 'M2','V2','V5','W1','W2','W3','W4'
,'W5','W6','W7','W8','W9','WZ','X2','X3','X4')
and p.status <> 5
and S.statusID IN (4,5,6,7,8,9,10,13)
and S.productid in (23)
group by b.code ,p.id , p.firstname,p.lastname,p.MiddleName,p.suffix,
p.company,pa.addressline1,pa.addressline2,pa.city, pa.state,pa.zipcode, s.status

View 2 Replies View Related

Update Query Running Very Slow

Apr 17, 2008

Hi all,

I'm having what you might call an optimisation issue - but I'm also not sure if my approach to this problem is right. I've spent the whole day trying various methods but none seem to be performing as admirably as I'd hoped.

Basically, here's the scenario:

1. Log files are being inserted into a SQL table via Log Parser 2.2.
2. I have a lookup table of ip address ranges to countries and other geographic data.
3. Once the log row has been inserted from Log Parser, I want to update the same log table with data from the lookup table.

The main problem seems to be the updating (the initial insert from Log Parser is lightning quick).

I initially wrote a trigger on AFTER INSERT on the log table that converted the actual user's IP address into IPNumber format using a simple algorithm, then pumped the IPNumber into a quick select query which retrieved the geolocation data. Then, in the same trigger, there was an update statement which basically said:

update dbo.Logs
set [Country] = @Country
where [IpNumber] = @IpNumber and [Country] = Null

Therein lies the problem. The update statement slows everything down to almost a standstill and also seems to obtain a lock on the table.

Critical factors:

1. The log table must remain readable.
2. The query must execute in seconds -- not over half hour :)

I've experimented with various combinations of indexing, so far to no avail.

Any suggestions would be very much appreciated.

Regards

View 10 Replies View Related

Adapting Running Totals To Query

Jul 8, 2013

I'm trying to adapt a formula for running totals to my Query, have some difficulties in declaring the tables correctly.

Formula: SELECT Ordinal, QTY, QTY+COALESCE((SELECT SUM(QTY)
FROM Table b
WHERE b.Ordinal < a.Ordinal),0) AS RunningTotal
FROM Table a
ORDER BY Ordinal

Now my Table is rather lengthy and is described by this query:

Select X.Ord, X.QTY
From (Select.... )X

Now in order to adapt the formula for running totals I did:Select X.Ord, X.QTY, X.QTY+COALESCE((SELECT SUM(X.QTY)

FROM X b
WHERE b.Ord < a.Ord),0) as RunningTotal
From (Select....)X a
Order by X.Ord

It gives my an ncorrect syntax error near a. I guess I miss the (double) declaration of the Table.

View 4 Replies View Related

Running Query From User Input

Jan 11, 2006

I would like to setup a query where the user is firstly prompted to input the information e.g. if they are trying to locate a particular person from a telephone database they would be prompted to enter the surname for that person.

View 4 Replies View Related

Running A Housekeeping Query Every Week

Aug 9, 2007

anyone any pointers on how to set up a query that will run every week? just to clean up the database a bit

thanks

View 1 Replies View Related

Calculating Query Running Time...

Dec 19, 2007

Hi all
As you know when you run a piece of TSQL scrypt in Query Analizer
at the bottom of the page , sql-server will show you the Time of completion of your code....is there any way to capture this time
from SQL-Server environment and use it in the Front-End Application
to inform the user?

Kind regards.

View 2 Replies View Related

Large Long Running Query

Mar 20, 2008



The query show below is designed to use seasonal profiles to compute 53 weeks of forecast data and then from that compute the number of weeks of supply of each item at each location. The query works but the volume of data produced (20+M rows) is substantial. If I limit the CTE to a single location, it run is 2 seconds and returns 41,000 rows. But when run for all locations and items, it runs for more than 4 hours. Would I do better converting the CTE to a sub-query and adding an index to improve the performance of the main query?


WITH Forecast AS

(SELECT Location_Idx

,Item_Idx

,Week_Code

,(CAST(AnnualQty AS DECIMAL(9))/53.0)*[Profile] AS fcst

FROM dbo.FactReplenishmentProfile rp

INNER JOIN dbo.FactSeasonalProfile sp

ON sp.SeasonalProfile_Idx = rp.SeasonalProfile_Idx

)

SELECT fcst1.Location_Idx

,fcst1.Item_Idx

,fcst1.Week_Code

,fcst1.fcst AS WeekQty

,SUM(fcst2.fcst) AS CumQty

FROM Forecast fcst1

INNER JOIN Forecast fcst2

ON fcst2.Location_Idx = fcst1.Location_Idx

AND fcst2.Item_Idx = fcst1.Item_Idx

AND fcst2.Week_code <= fcst1.Week_Code

GROUP BY fcst1.Location_Idx,fcst1.Item_Idx,fcst1.Week_code,fcst1.fcst

View 4 Replies View Related

Transact SQL :: Query On Running Value (difference)

Jun 18, 2015

I have a table that will be loaded over night everyday and I need to write a query on running value difference ?

List of Columns (ID, Branch ,Group, Date, Value)

ID    Branch   Group   Date                   Value
1        A           C      2015-06-01            10
2        A          C       2015-06-02            15
3        A          C       2015-06-03            25
4        A          C       2015-06-04            20
5        B          D       2015-06-01            20
6        B          D       2015-06-02            25
7        B          D       2015-06-03            10
8        B          D       2015-06-04            20

I want the Output like below with a Running value difference in comparison to previous day.

ID    Branch   Group   Date          Value    Running Value
1        A           C      2015-06-01            10         10
2        A          C       2015-06-02            15         05
3        A          C       2015-06-03            25         10
4        A          C       2015-06-04            20         -5
5        B          D       2015-06-01            20         20
6        B          D       2015-06-02            25         05
7        B          D       2015-06-03            10        -15
8        B          D       2015-06-04            20         10

Basically I need to compare the previous day and show the difference. How can I do this in SQL 2008 r2?

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved