sql-server-2008-r2

T-SQL Multiple grouping

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:54:01
I have follwing data : Product Price StartDate EndDate Apples 4.9 2010-03-01 00:00:00.000 2010-03-01 00:00:00.000 Apples 4.9 2010-03-02 00:00:00.000 2010-03-02 00:00:00.000 Apples 2.5 2010-03-03 00:00:00.000 2010-03-03 00:00:00.000 Apples 4.9 2010-03-05 00:00:00.000 2010-03-05 00:00:00.000 Apples 4.9 2010-03-06 00:00:00.000 2010-03-06 00:00:00.000 Apples 4.9 2010-03-09 00:00:00.000 2010-03-09 00:00:00.000 Apples 2.5 2010-03-10 00:00:00.000 2010-03-10 00:00:00.000 Apples 4.9 2010-03-11 00:00:00.000 2010-03-11 00:00:00.000 Apples 4.9 2010-03-12 00:00:00.000 2010-03-12 00:00:00.000 Apples 4.9

How often is Stored Procedure xyz, or Table Valued Function Used – SQL Server 2008 R2

杀马特。学长 韩版系。学妹 提交于 2019-12-01 06:47:34
问题 We have a number of Views, Stored Procs, Table Values and Scalar functions. How can we see how often or even how many times these have been called from within SQL Server? Do we need to edit each one to update a table on each call to get this, or does SQL server keep this information somewhere? 回答1: This is one of Glenn Berry's DMV queries. It counts how many times a cached stored procedure has been executed (filtered by the current database): SELECT TOP(25) p.name AS [SP Name], qs.execution

Is there any way to overcome parameter sniffing in SQL Server?

耗尽温柔 提交于 2019-12-01 06:15:10
I came across parameter sniffing when one of my queries took a much longer time to execute than expected. When I delved a little deeper into this problem I came to know that: When first time query gets executed it (SQL Server) creates execution plan for that query and for other n number of times same query executed and if it has large variance in result set with first time execution then parameter sniffing problem occurs". This was in my scenario. Now my question is, is there any way or workaround to overcome parameter sniffing in SQL Server in these scenarios? I know by running sp_updatestats

SQL Server search in nvarchar & ntext

混江龙づ霸主 提交于 2019-12-01 06:09:43
I'm using SQL Server 2008 as my database engine in a VS2010, C# ASP.NET web app. My project is Farsi (Persian) so I've used nvarchar and ntext as my data types. I use following query to find rows from my database but nothing is returned, while I have a row with the specified keyword. Of course my keyword is in Persian (unicode). What is going wrong here? Is it because of using Farsi language? How can I search in nvarchar and ntext columns containing unicode characters? myCommand = new SqlCommand("select * from tblArticle where name LIKE '%" + txtSearch.Text + "%'", SQLConnection); You should

Calculate Actual Downtime ignoring overlap in dates/times

走远了吗. 提交于 2019-12-01 06:06:49
问题 I'm trying to work out how to calculate actual downtime for various applications from data I'm storing within a table. At the moment I'm just calculating the difference between DowntimeStart and DowntimeEnd which is shown in the DowntimeMinutes. The problem is that if there is a cross-over in times as separate components are down, it should count the total ignoring the over-lap. What I expect is shown in the Expected column. Any ideas on how a query could be put together to achieve this?

Conversion failed when converting date and/or time from character string in SQL SERVER 2008

淺唱寂寞╮ 提交于 2019-12-01 05:44:30
I have below SQL. UPDATE student_queues SET Deleted=0, last_accessed_by='raja', last_accessed_on=CONVERT(VARCHAR(24),'23-07-2014 09:37:00',113) WHERE std_id IN ('2144-384-11564') AND reject_details='REJECT' when I ran the above SQL the below exception has been throwed. Conversion failed when converting date and/or time from character string. If you're trying to insert in to last_accessed_on , which is a DateTime2 , then your issue is with the fact that you are converting it to a varchar in a format that SQL doesn't understand. If you modify your code to this, it should work, note the format of

'Create VIEW' must be the only statement in the batch

时光总嘲笑我的痴心妄想 提交于 2019-12-01 05:21:22
I have the following SQL: ALTER PROCEDURE [dbo].[usp_gettasks] @ID varchar(50) AS declare @PDate Date WHILE (DATEPART(DW, @PDate) = 1 OR DATEPART(DW, @PDate) = 7 ) BEGIN set @PDate = DATEADD(day, 1, @PDate) END CREATE VIEW tblList AS select tt.ItemOrder,tt.DisplayVal, DATEADD(day, tt.DaysDue, @PDate) from tblLine tt where tt.ID = 1 I get the following message: Incorrect syntax: 'Create VIEW' must be the only statement in the batch I tried putting GO before Create View , but then it can't recognize the value of PDate . To create a view in a stored procedure, you need to do this in dynamic SQL

T-SQL Multiple grouping

主宰稳场 提交于 2019-12-01 04:53:26
问题 I have follwing data : Product Price StartDate EndDate Apples 4.9 2010-03-01 00:00:00.000 2010-03-01 00:00:00.000 Apples 4.9 2010-03-02 00:00:00.000 2010-03-02 00:00:00.000 Apples 2.5 2010-03-03 00:00:00.000 2010-03-03 00:00:00.000 Apples 4.9 2010-03-05 00:00:00.000 2010-03-05 00:00:00.000 Apples 4.9 2010-03-06 00:00:00.000 2010-03-06 00:00:00.000 Apples 4.9 2010-03-09 00:00:00.000 2010-03-09 00:00:00.000 Apples 2.5 2010-03-10 00:00:00.000 2010-03-10 00:00:00.000 Apples 4.9 2010-03-11 00:00

The Transaction Ended In The Trigger The Batch Has Been Aborted

喜你入骨 提交于 2019-12-01 04:28:01
I am using Sql Server 2008 . I have a Trigger which updates my two other tables. I have read the Stack over flow this link enter link description here , but it does not full fill my needs. Below is my Trigger ALTER TRIGGER [Inventory].[StockUpdationOnIssue] ON [Inventory].[StockIssueDetails] AFTER INSERT AS BEGIN BEGIN TRY BEGIN TRAN INSERT INTO TableA (col1, col2,col3 ) SELECT I.col1,I.col2,si.col3 FROM inserted I INNER JOIN Inventory.StockIssue SI ON SI.StockIssueId = I.StockIssueId INSERT INTO TableB (col1, col2,col3 ) SELECT I.col1,I.col2,si.col3 FROM inserted I INNER JOIN Inventory

SQL 2008 R2 - Time-Based Triggers?

人盡茶涼 提交于 2019-12-01 04:24:32
问题 Is it possible to have a stored procedure or set of SQL code run periodically by specifying a time-based trigger in SQL Server? 回答1: Not directly, but look at SQL Jobs. A job is a specified series of operations performed sequentially by SQL Server Agent. A job can perform a wide range of activities, including running Transact-SQL scripts, command-line applications, Microsoft ActiveX scripts, Integration Services packages, Analysis Services commands and queries, or Replication tasks. Jobs can