In this regard need to show the recoveries made by each Manager from their relevant customers? In other words, instead of the customer-wise balances need to show the difference between the balances comparing the dates. The dates are in month-end formats.For example, if Customer A has a record of $10,000 as on January 10, 2015 and the same has two entries on February 28, 2015 with balances of $4,000 and $4,000, instead of balances, need to show ($2,000). Similarly, in case of March 31, 2015 reflecting three entries amounting to $3,000 each, need to reflect a positive amount of $1,000. And where the same customer has no entry on April 30, 2015, need to reflect a negative amount of $9,000.These entries thereafter being grouped on Manager level.
12/1/07 What i'm trying to do is return a result with total charges from 3 months previous based on a date parameter or just as a whole for that matter. For example:
If my date parameter is 6/14/07, i'd like my total charges to be 15 (6+5+4). If my date parameter is 7/10/07, the charges would be 18 (7+6+5)
I hope that makes sense of where i'm going with this. I've played with this using the "Guru's Guide" solution by Ken Henderson, but still to no avail yet. Here's his code syntax:
Code Block
SELECT a.DayCount, a.Sales, SUM(b.Sales) FROM Sales a CROSS JOIN Sales b WHERE (b.DayCount <= a.DayCount) AS RunningTotal GROUP BY a.DayCount,a.Sales ORDER BY a.DayCount,a.Sales Here is the result set i'm looking for:
Charges
Date
1
1/1/07
2
2/1/07
6
3/1/07
9
4/1/07
12
5/1/07
15
6/1/07
18
7/1/07
21
8/1/07
24
9/1/07
27
10/1/07
30
11/1/07
33
12/1/07 Each date's charges are a culmination of 3 months worth of charges.
Any help would be greatly appreciated. I'll be trying to figure this one out concurrently and if i do, i'll post back!
I have a server with two test instances of a data base. I have a query which creates a temp table, inserts 29 rows, perform 4 update queries to add counts and then dumpps out the results. This entire query script runs 1.33 minutes on one instance and 2.5 minutes on the other. On the production server this query now runs in 9 seconds. If I run any one of the test updates individually they execute under 2 seconds, just like the production server. THe results are repeatable.
All are SQL 7 with all service packs on NT4 sp6. Both test data bases are backups of production from last week. I suspect some kind of caching/buffer problem, but I do not know what to look for. I am not a DBA so I have no idea what role TEMPDB plays may play in this.
Can anyone give us ideas on where to look for the performance difference? Will our impending upgrade to SQL2K solve this problem or make it worse? Any ideas would be appreciated.
I am a newbie when it comes to MS SQL Server administration and I am hoping you can help me out. We are migrating from a shared webhosting platform to our own internal dedicated web / MS SQL (2005) server and have encountered an error that appears to be stemming form Query Syntax.
In our old system we could simply query via the following format:
"Select [Column] from [Table Name]"
But on the SQL Server I just set up we have to query via this format:
"Select [Column] from [Database Name].[Table Name]"
We have literally hundreds of preprogrammed Queries and it would be quite difficult to change them all. Does anyone know how I can set up SQL Server to run so that our quieries do not require the DatabaseName in the statement? I have placed the connection code below, if that helps any.
Set objConn= Server.CreateObject("ADODB.Connection") objConn.Open "Provider=SQLOLEDB; Data Source =; Initial Catalog =; User Id =; Password=" Set objRec = Server.CreateObject("ADODB.Recordset").
I hope someone can help, I usually just need to do simple queries, and am fine with that, but this is a bit over my head without a few pointers in the right direction.
I have a table that stores log results from pieces of hardware that contact an internet server periodically.
For simplification, this contains:
LogID SystemID DeviceID ContactDateTime Notes
Each device contacts the server about once every 5 minutes, and there are about 100 devices in 6 systems.
What I need to do is find out, for a certain date time range, things like:
1. the average time between comunication for any one device 2. the longest time between communication for any one device 3. average time between communications for all devices in a system.
We currently do this by downloading all the logs and working through them programmatically on the server, but as you can imagine, it is a very large amount of information, and it would be much more efficient if this could be done on the SQL server.
Hi, I am pretty new to Analysis Services and I have come across a small problem to do with point in time balances, I guess that this is similar shiver72's post titled 'Date Range Problem'. I am not really after a solution as such (although that would be great :-), more interested in a pointer to some resource(s) which I can read up on myself.
Here is the scenario:
A student enrols into a course that has a start and finish date. This enrolment has a certain value based upon its length, the course type etc which means that each enrolment's 'value' can vary at any time between the start and finish dates.
For example a student may enrol in a full year basket weaving course with a value of 0.0500, they then enrol in a part year course titled 'Dimensional Modelling 101' with a value of 1.000
The client wishes to know at any point in time the 'value' of their enrolments. These values can vary due to a student starting or finishing their enrolment, withdrawing, having their enrolment suspended etc, etc
Now, in the Data Warehouse Toolkit it mentions point in time balances in the 'Financial Services' section but it uses SQL to prove the point which is no use to me because I am using MS Analysis Services to dynamically create the result.
As it says in the book its no use creating a row in the fact table to represent the value for each day that the enrolment is in effect because with 400,000 enrolments that works out to over 140 million rows. The alternative is to create one row for each occurence of the variation in the value of the enrolment and then the facts would be completely additive and useful.
I would be looking at using something similar to the following:
fact table ---------- fkdate value fksudent fkcourse <possibly some degenerate measure like the UID of the course enrolment held in the source system>
dimensions ---------- Student - and of course a whole heap of related dimensions like gender, age, ethnicity etc Course
For example given the above information the fact table would look like this:
(Student UID is 2005123, course UIDs are 1000 and 1001)
That way I can run a query at, say 15-JUN-2005 and sum the values and it will come out with the correct balance - and yes I know that this idea is straight out of the book :-)
OK, if you've read to this point then I take it that you are an extremely patient person and therefore will forgive my next question.
My question is this, my clients use simple tools like Excel pivot tables to gouge the information they want out of the warehouse, sure, I can write an MDX query to get a point in time balance (just as soon as I learn a bit more about it) but is there _any_ way/means/algorithm/trick/way to hold your head to one side, that I can use so that they can still just 'drag and drop' using the pivot table service as opposed to having to me having to create an MDX-based report for them ?
I am having trouble with a VIEW. I modify the view to add a sort criteria. I can Execute the SQL and get the results I am looking for. I save the VIEW. Then if I open the VIEW using the OPEN VIEW menu option(right clicking the VIEW name) the sort order I set does not work. Please help.
Using Microsoft SQL Server Management Studio Express to access the SQL Server 2005
I have a client that I provide financial modelling services to (using Excel). They have a requirement to start capturing subscriber movements in their SQL DB. how the table should be set-up and how to extract the necessary movements report. This is largely so that I may include these components in some of the financial models that I am working on.
Subscribers are reported as follows:
Opening subs (the prior periods closing balance; or the sum of new sales at point of 1st entry)
+ New Sales (new subs)
+ Upgrades (movement from a lower product package to the associated package)
- Downgrades (movement to a lower product package from the associated package)
- Churn (subscriber losses)
Closing Balance
All transactions are captured against a specific product package, on a specific date (ymd), and for an associated platform (e.g. digital TV, broadband TV, cable TV).
I believe we only need to capture new sales, upgrades, downgrades and churn. And then used a SP to compile the movements behaviour as described above.
So perhaps the table would appear as follows:
Platform Package Date Movement Value
DTV PROD 1 2014-11-02 New Sales 8
DTV PROD 1 2014-11-02 Upgrades 1
[code]....
So I am assuming that given a table such as the above, we could write a SP to produce an output such as (note, below looks at monthly total so will not agree back to sample above which contains only 2 days):
Platform Package Movement September October November
DTV PROD 1 OPEN 600 676 776
DTV PROD 1 New Sales 92 106 88
[code]....
how one is best to accumulate the balances given that the open date for any given reporting period is in fact an accumulation of all balances since day 1.
How does one typically capture this type of thing in SQL?
there is any service or technique to reflect database changes to form?
am mean if there is two people update same data and one of them
does the update i need (search) on service in sql server or .net that(or triger) that can automatically reflect changes to the form control that display data automatically when data changes before the another persone make second aupdate, so he can see the update made by the first person pefore he make another update.
I'm working with a table called SALFLDGAMS where it has two columns that I need to work with. One of the columns is Period which has years from 2000 to 2005 and the other column is called amount which has the balance for that year. Let me explain in a little more detail. There are account codes associated with the years as well so there will be many places where for example the year 2000 will show up with a given value. What I'm trying to do is to create a view which has a BeginBalance column which adds lets say all the values for 2000 and sticks them to 2001. So what I'm saying is all the values from the previous year I want them in the current year. All in one column. Thanks for the help guys.
For each customer, I want to add all of their telephone numbers to a different column. That is, multiple columns (depending on the number of telephone numbers) for each customer/row. How can I achieve that?
I want my output to be
CUSTOMER ID, FIRST NAME, LAST NAME, TEL1, TEL2, TEL3, ... etc
Each 'Tel' will relate to a one or more records in the PHONES table that is linked back to the customer.
I have a query that performs a comparison between 2 different databases and returns the results of the comparison. It returns 2 columns. The 1st column is the value of the object being compared, and the 2nd column is a number representing any discrepancies.What I would like to do is use the results from this 1st query in the where clause of another separate query so that this 2nd query will only run for any primary values from the 1st query where a secondary value in the 1st query is not equal to zero.I was thinking of using an "IN" function in the 2nd query to pull data from the 1st column in the 1st query where the 2nd column in the 1st query != 0, but I'm having trouble ironing out the correct syntax, and conceptualizing this optimally.
While I would prefer to only return values from the 1st query where the comparison value != 0 in order to have a concise list to work with, I am having difficulty in that the comparison value is a mathematical calculation of 2 different tables in 2 different databases, and so far I've been forced to include it in the select criteria because the where clause does not accept it.Also, I am not a DBA by trade. I am a system administrator writing SQL code for reporting data from an application I support.
I have a column colC in a table myTable that has a value (e.g. '0X'). The position of a non-zero character in column colC refers to the ordinal position of another column in the table myTable (in the aforementioned example, colB).
To get a column name (i.e., colA or colB) from table myTable, I can join ("ON cte.pos = cn.ORDINAL_POSITION") to INFORMATION_SCHEMA.COLUMNS for that table catalog, schema and name. But I want to show the value of what is in that column (e.g., 'ABC'), not just the name. Hoping for:
COLUMN_NAME Value ----------- ----- colB 123 colA XYZ
I've tried dynamic SQL to no success, probably not executing the concept correctly...
I am trying to optimize a stored procedure in SQL 2008. When I look at an actual execution plan generated from when I run it in SSMS it shows a table being used in the plan that has no relation to what is actually in the query script and this is where the biggest performance hit occurs.
I've never seen a table show up before that wasn't part of the query. why this might occur and how to correct it? I can't just change the query script because the table in question isn't there.
I am curious to what major differences there are between these two versions. Trying to decide whether or not to purchase the SQL 6.5 training kit from Microsoft or not. If the code and utilities are the same, then I could probably still learn from the 6.5 version. Any thoughts, suggestions will be greatly appreciated.
I am having the following problem AFTER converting to VS2008 from VS2005 and SQLCE 3.5 from 3.01:
SQL CE db file has a table called Court0 with various columns of type float. I populate the values by copying floats from another table/tables. I do this via ado.net using this code snippet:
We have a database that when an update is released (and this is very often) the release notes don't cover most of the actual changes. Every time groups of our custom queries and reports get broken due to database changes. Does anyone know how to compare two databases and get a report of the differences between them? I can either have the two versions on the same server or on different servers if that makes a difference.
I'm hoping for something where you input @oldversion, @newversion
I have just converted some Access VBA code to a sproc. I'm finding that for some reason the rounding is different: eg. ROUND(17 * 97995 / 1000,2) = 1665.915 before Rounding
SQL SProc: 1665.91 Rounds down ADP VBA: 1665.92 Rounds up
/* Objects in Company1 Missing in Company2 */ Select 'Table Objects in Company1 but are not in Company2' select Left(a.name,30), a.refdate from sysobjects a Where a.xtype = 'U' and a.name like 'TBL%' and Not Exists (Select 1 From ____________.dbname.dbo.sysobjects b where a.name = b.name)
/* Objects in Company2 Missing in Company1 */ Select 'Table Objects in Company2 but are not in Company1' select Left(a.name,30), a.refdate from ____________.dbname.dbo.sysobjects a Where a.xtype = 'U' and a.name like 'TBL%' and Not Exists (Select 1 From sysobjects b where a.name = b.name)
/* Column Differences */
Select 'Column Differences between like named tables'
select Left(x.TabName,30) as TableName, Left(x.ColName,30) as ColumnName , Left(x.DataType,15) as Company1DataType, x.length as Company1Length, x.refdate as Company1RefDate , Left(y.DataType,15) as Company2DataType, y.length As Company2Length, y.refdate as Company2RefDate from ( Select a.name as TabName, b.name as ColName, b.length, c.name as DataType, a.refdate from sysobjects a, syscolumns b, systypes c where a.id = b.id and b.xusertype = c.xusertype and a.xtype = 'U' and a.name like 'TBL%') As x , ( Select a.name as TabName, b.name as ColName, b.length, c.name as DataType, a.refdate from ____________.dbname.dbo.sysobjects a, ____________.dbname.dbo.syscolumns b, ____________.dbname.dbo.systypes c where a.id = b.id and a.xtype = 'U' and b.xusertype = c.xusertype and a.name like 'TBL%') As y Where x.TabName = y.TabName and x.ColName = y.ColName and (x.length <> y.length or x.DataType <> y.DataType)
/* Column Differences */ Select 'Column in Company1.com not in Company2'
Select Left(a.name,30) as TableName, Left(b.name,30) as ColumnName, b.length, c.name, a.refdate from sysobjects a, syscolumns b, systypes c where a.id = b.id and b.xusertype = c.xusertype and a.xtype = 'U' and a.name like 'TBL%' and Not Exists ( Select 1 from ____________.dbname.dbo.sysobjects d, ____________.dbname.dbo.syscolumns e where d.id = e.id and a.xtype = 'U' and a.name like 'TBL%' and a.name = d.name and b.name = e.name) Order by 1, 2
/* Column Differences */ Select 'Column in Company2 not in Company1.com'
Select Left(a.name,30) as TableName, Left(b.name,30) as ColumnName, b.length, c.name, a.refdate from ____________.dbname.dbo.sysobjects a, ____________.dbname.dbo.syscolumns b, ____________.dbname.dbo.systypes c where a.id = b.id and b.xusertype = c.xusertype and a.xtype = 'U' and a.name like 'TBL%' and Not Exists ( Select 1 from sysobjects d, syscolumns e where d.id = e.id and a.xtype = 'U' and a.name like 'TBL%' and a.name = d.name and b.name = e.name) Order by 1, 2
--Select 'Table Objects that are still in use in both Company2 and Company1' --select Left(a.name,30), a.refdate from sysobjects a, ____________.dbname.dbo.sysobjects b --where a.name = b.name and a.xtype = 'U'
What's the difference between using CREATE TABLE #TempTable and DECLARE @Table TABLE for temp tables and are there any advantages or disadvantages to using one over the other?Thanks
Is there any tool to find the differences between the two databases. I would like to know the differences in developmental server and Production server. if the developers create any new objects, I want to migrate them to production server.
Can we do it in sql server 200 or do we need to have separate tool.
I am updating a db with data from a file, in this data we have new info, info that has been updated and info that is to be removed from the db. Now I was wondering which approach results in better performance/shorter executin time:
1. first update excisting values, then insert new ones, and last delete cancelled data
or
2. delete cancelled data and data that will be updated, then insert new and updated info
I get all this data from a file, in that file all rows are similar and there is one column that defines if the data is new, updated or to be deleted (thus all the updates also include the information for the enty that has not been altered).
I am kind of baffeled. I have a table with a column of 8 varchar in 2000 and the same in 6.5. When I insert into 2000 with a data length of more than 8 chars via Cold Fusion into the table, it fails. The same Cold Fusion program inserts into the 6.5 table, but truncates the data but does not fail. Does anyone know why this happens. Thanks, Newbie.
I have written the SQL below and need to change the case. I need to say that if today’s date (get date) is between <> 4 weeks of sv_latest_appraisal then = Outstanding. Can this be done in SQL? I know it is very specific so not sure. Please help! Sam
SELECT Employee.FORENAME AS Forename, Employee.SURNAME AS Surname, Employee.LOCATION AS Location, Employee.DEPARTMENT AS Department, Employee.STARTDATE AS Startdate, Sv_latest_appraisal.NEXT_APP AS Next_app, Sv_latest_appraisal.USR_EAR_TYPE AS Usr_ear_type, Sv_latest_appraisal.USR_EAR_TYPE_NEW AS Usr_ear_type_new, CASE WHEN Sv_latest_appraisal.NEXT_APP <= getdate() THEN 'OVERDUE' WHEN Sv_latest_appraisal.NEXT_APP >= getdate() THEN 'NOT DUE' WHEN Sv_latest_appraisal.NEXT_APP = getdate() THEN 'DUE TODAY' ELSE 'UNKNOWN' END FROM (dbo.EMPLOYEE AS Employee INNER JOIN dbo.SV_latest_appraisal ON Employee.EMPLOY_REF = Sv_latest_appraisal.EMPLOY_REF) INNER JOIN dbo.JOB AS Job ON Employee.JOB_REF = Job.JOB_REF WHERE (Employee.LEAVER = 0)AND (Employee.LOCATION LIKE 'GE')
I want to generate a query that returns a the following results with an extra column named 'KMDifference' which is the difference between 'ArrivalKM' from last day and 'DepartureKM' from today.