sql-server-2005

SQL query executing slowly (for some parameter values)

大憨熊 提交于 2019-12-13 15:27:15
问题 I have a SQL Server 2005 database with several tables. One of the tables is used to store timestamps and message counters for several devices, and has the following columns: CREATE TABLE [dbo].[Timestamps] ( [Id] [uniqueidentifier] NOT NULL, [MessageCounter] [bigint] NULL, [TimeReceived] [bigint] NULL, [DeviceTime] [bigint] NULL, [DeviceId] [int] NULL ) Id is the unique primary key (Guid.Comb), and I have indexes on both DeviceId and MessageCounter columns. What I want to do is find the last

executed an oracle stored procedure from sql server using the open query function

a 夏天 提交于 2019-12-13 15:26:45
问题 Can you confirm if you have successfully executed an oracle stored procedure from sql server using the open query function. If yes, How? because I am having problems executing stored procedures with arguments using the OPENQUERY Function. 回答1: Finally tracked down a few solutions – the key to the problem (for us) is that by default RPCs are disabled for linked servers. The parameters for Rpc, Rpc Out, and Use Remote Collation need to be set to true. More info: http://blog.sqlauthority.com

Is there meta data I can read from SQL Server to know the last changed row/table?

懵懂的女人 提交于 2019-12-13 15:03:10
问题 We have a database with hundreds of tables. Is there some kind of meta data source in SQL Server that I can programatically query to get the name of the last changed table and row? Or do we need to implement this ourselves with fields in each table called LastChangedDateTime , etc.? 回答1: In terms of finding out when a table last had a modification, there is a sneaky way that can work to access this information, but it will not tell you which row was altered, just when. SQL Server maintains

Calculate the each product(Inkcode) stock

强颜欢笑 提交于 2019-12-13 14:52:09
问题 I have 2 tables Tblinkreceiving and Tblinkdelivery. I want to display the Stock balance for each inkcode.I tried the below sql join query but the calculation is wrong for many inkcodes when i cross check in manual calculation.Where it went wrong ? select r.inkcode, SUM(r.quantity) Stock-In, SUM(d.quantity) Stock-out, (SUM(r.quantity) - SUM(d.quantity)) Stock-Balance from Tblinkreceiving r,Tblinkdelivery d where r.inkcode=d.inkcode group by r.inkcode; 回答1: WITH i AS ( SELECT inkcode, SUM

Why is my SQL 'NOT IN' clause producing different results from 'NOT EXISTS'

自闭症网瘾萝莉.ら 提交于 2019-12-13 14:45:34
问题 I have two SQL queries producing different results when I would expect them to produce the same result. I am trying to find the number of events that do not have a corresponding location. All locations have an event but events can also link to non-location records. The following query produces a count of 16244, the correct value. SELECT COUNT(DISTINCT e.event_id) FROM events AS e WHERE NOT EXISTS (SELECT * FROM locations AS l WHERE l.event_id = e.event_id) The following query produces a count

Pivot SQL query - Show Date in column

拈花ヽ惹草 提交于 2019-12-13 14:20:34
问题 my current query return the below result What I need is I have to display date in column header. I know it have to be done using Pivot Example: if we want to display month in column header then query will be something like.. SELECT [January], [February], [March] FROM ( SELECT [Month], SaleAmount FROM Sales ) p PIVOT ( SUM(SaleAmount) FOR [Month] IN ([January],[February],[March]) ) AS pvt and I think my resultant query should be look like Pivot ( (Price) FOR [DateVal] IN (What will be here?) )

Multi-part identifier could not be bound

谁说胖子不能爱 提交于 2019-12-13 14:09:41
问题 I know that there are several questions around this exception on SO, but nothing seen that helps me. I have following query giving me a "Multi-part identifier 'claim.fiData' could not be bound" -Exception: SELECT claim.idData FROM tabData as claim INNER JOIN dbo._previousClaimsByFiData(claim.fiData) AS prevClaim ON prevClaim.idData=claim.fiData GROUP BY claim.idData HAVING(prevClaim.fiMaxActionCode IN (8, 23, 24) and prevClaim.Repair_Completion_Date >= DATEADD(day,-90,prevClaim.Repair

Execute sql file on SQL Server using C#

百般思念 提交于 2019-12-13 13:41:38
问题 I have many files for procedures, views, functions, etc. I want to execute these files (creating components) in appropriate database on SQL Server 2005/2008. Also the point is I want to execute them using C#. Another point to mention, I want the application to be such that I can execute this files on a remote SQL Server too. Also client machine may not have osql,sqlcmd command tool. Can someone please guide me on this. 回答1: This depends on what sort of files they are. If, for example, they

Web.config Authentication Error

£可爱£侵袭症+ 提交于 2019-12-13 13:25:45
问题 I am using SQLServer2005 and VS2008. My connection string in web.config is: add name="library" connectionString="Data source=KMT; Initial Catalog=Library;Integrated Security=SSPI" Here, KMT is my server name, Library is my database. When I run my page through VS2008 localhost, it's fine. However, when viewing through IIS it shows an error message like "login failed for user, 'KMT/ASP.NET'". My sqlserver authentication mode is windows and it's ok in web.config. What will be the solution? 回答1:

Different Execution Plan for the same Stored Procedure

旧街凉风 提交于 2019-12-13 13:22:17
问题 We have a query that is taking around 5 sec on our production system, but on our mirror system (as identical as possible to production) and dev systems it takes under 1 second. We have checked out the query plans and we can see that they differ. Also from these plans we can see why one is taking longer than the other. The data, schame and servers are similar and the stored procedures identical. We know how to fix it by re-arranging the joins and adding hints, However at the moment it would be