sql-server-2005

SQL SERVER Transaction log full

送分小仙女□ 提交于 2020-01-02 07:43:28
问题 How to free Transaction log space in SQL SERVER 2005: I have Transaction log size = 70 GB and there four transaction logs 1,2,3,4 in different drives. Through DBCC SQLPERF(LOGSPACE) I found that the transaction log is Full (uses 100 %) and I want to free up the space in transaction log and I don't want T-log backup. I don't have space to backup the transaction log. And my DB is in Replication state. How can I free up the Transaction log or Instead of 3 transaction log files, can I have only

SQL order results by number of fields matched

筅森魡賤 提交于 2020-01-02 07:11:44
问题 Bit of a complicated SQL question here. I currently have a SELECT statement which matches several fields, like this. SELECT field1, field2, field3, field4, field5 FROM table WHERE field1 = 'variable 1' AND field2 = 'variable 2' AND field3 = 'variable 3' AND field4 = 'variable 4' AND field5 = 'variable 5' I would like to modify the statement so that it uses OR's instead of AND's so that it selects all records which match any of the fields. The next step is to rank the results using a scoring

Improve Sql Query with select max() function in where clause

蓝咒 提交于 2020-01-02 06:58:07
问题 The purpose of this query is to bring back products and their prices for products on sale and the price should be from the date closest but not equal to the date passed in, essentially the most recent price available. There are not price records for every day. Something feels a little wrong about having the aggregate select statement in the where clause. Is there a better way to do this? Maybe in the join criteria? select p.ProductName, pp.Price, pp.Date, from product p inner join

How can you tell if a Sql Server Stored Procedure returns records

流过昼夜 提交于 2020-01-02 05:40:10
问题 Within tsql I'm calling a tsql stored procedure that returns a record set. I want to be able to tell if the record set is empty or not empty. For some reason @@rowcount always returns 1. What is the best way to do this? One more thing I'm not in a position to edit this stored procedure. 回答1: Use @@rowcount in the inner stored proc, pass back out as an output paramter. Use @@rowcount immediately after the SELECT in the inner stored proc. And call like this: EXEC dbo.InnerProc @p1, ...,

TSQL: Cannot perform an aggregate function AVG on COUNT(*) to find busiest hours of day

安稳与你 提交于 2020-01-02 05:26:08
问题 Consider a SQL Server table that holds log data. The important parts are: CREATE TABLE [dbo].[CustomerLog]( [ID] [int] IDENTITY(1,1) NOT NULL, [CustID] [int] NOT NULL, [VisitDate] [datetime] NOT NULL, CONSTRAINT [PK_CustomerLog] PRIMARY KEY CLUSTERED ([ID] ASC)) ON [PRIMARY] The query here is around finding the distribution of visits BY HOUR of the day. We're interested in seeing the distribution of the average number of visits for the hour in a given date range. The query results would be

Return one of two columns in a view - whichever one is not null

大城市里の小女人 提交于 2020-01-02 04:48:05
问题 I have a table with three columns: ColumnA ColumnB ColumnC AAA NULL 123 BBB 222 NULL CCC NULL NULL I would like to create a SELECT statement which will return ColumnA, and then a second column which will either show the value of ColumnB unless ColumnB is null; otherwise it will show the value of ColumnC, even it it's NULL. Can I use an IF statement for that? Something like: SELECT ColumnA, IF(ColumnB IS NULL, ColumnC, ColumnB) FROM table **If I get this working, the next step would be to

System.IndexOutOfRangeException: Index was outside the bounds of the array [duplicate]

故事扮演 提交于 2020-01-02 04:10:09
问题 This question already has answers here : What is an IndexOutOfRangeException / ArgumentOutOfRangeException and how do I fix it? (4 answers) Closed 3 years ago . I am developing an ATM Software as a home work in which i want to know the total amount of transaction which is processed today, for this purpose I am writting the following code public decimal getDayTransaction(int accountid, string date, string transactiontype) { decimal totalamount = 0; int i = 0; string connectionString = "Persist

SQL Server Profiling how should I go about it?

空扰寡人 提交于 2020-01-02 04:08:11
问题 So I have used SQL Profiler before and I know how I can view what my LINQ queries are doing behind the scenes. Now, we are in the process of identifying queries that may take more time and need to be optimized or have some indexing. So, now when I view my LINQ queries in the profiler running it side by side there is lot of other data and queries that I dont care. Is there anyway the profiler or some other tools could sort the queries in the order of the largest time....so that I will work on

Sql Server Performance And Order Of Fields

情到浓时终转凉″ 提交于 2020-01-02 04:00:21
问题 does the order of fields creation in a table effect on the performance of commands on the table? If the answer is yes, can anyone discuss it? For example i have create a table like this create table Software(int id,alpha datetime,beta datetime,title nvarchar(100),stable datetime,description nvarchar(200) ) if i change it to create table Software(int id,alpha datetime,beta datetime,stable datetime,description nvarchar(200),title nvarchar(100) ) Is there any performance effect ? Is it clear?

SQL Server View Primary Key

五迷三道 提交于 2020-01-02 03:36:05
问题 Is there a way to give a view a primary key in sql server. I know it is possible in oracle. I am not concerned about updates its a read only view but someone else is using it in ms access so I would like the constraint that I know to be correct to be shown. 回答1: Yes, you can create an indexed view, which must have a primary key. Note, this will persist the view data to disk, which may or may not be what you are looking for. Also, creation of indexed views can also impact performance, both