sql-server-2008-r2

Distributed database transaction vs cross database transaction

不羁岁月 提交于 2019-12-01 01:51:51
问题 What's the different between Distributed database transaction and cross database transaction in SQL Server. I know that Distribute database transaction is a transaction between multiple database and can use by following query : BEGIN DISTRIBUTED TRANSACTION ... COMMIT TRANSACTION 回答1: A Cross database transaction occurs between 2 or more databases on the same server. It does not require the involvement of a DTC (Distributed Transaction Coordinator) A Distributed database transaction occurs

Percentile aggregate for SQL Server 2008 R2

扶醉桌前 提交于 2019-12-01 01:43:52
I'm using SQL Server 2008 R2. I need to compute a percentile value per group, something like: SELECT id, PCTL(0.9, x) -- for the 90th percentile FROM my_table GROUP BY id ORDER BY id For example, given this DDL ( fiddle ) --- CREATE TABLE my_table (id INT, x REAL); INSERT INTO my_table VALUES (7, 0.164595), (5, 0.671311), (7, 0.0118385), (6, 0.704592), (3, 0.633521), (3, 0.337268), (0, 0.54739), (6, 0.312282), (0, 0.220618), (7, 0.214973), (6, 0.410768), (7, 0.151572), (7, 0.0639506), (5, 0.339075), (1, 0.284094), (2, 0.126722), (2, 0.870079), (3, 0.369366), (1, 0.6687), (5, 0.199456), (5, 0

SSRS sum max by group

南楼画角 提交于 2019-12-01 01:39:52
问题 I have an SSRS report that looks like this (with additional columns such as sales) with rows grouped by region and location. The goal for the locations is the max for each location as in my query the goal appears on each sales record that I'm summing. =Max(Fields!goal.Value) The goal for the regions is the sum of the max for each location in that region group. =Sum(max(Fields!goal.Value, "LocationName"), "region") Those first two are no problem, but I'm having difficulty getting the grand

SQL Server Import Wizard “workgroup information file” error when importing Access .mdb

隐身守侯 提交于 2019-12-01 01:35:42
问题 Is it possible to import an MS Access. mdb file into SQLExpress if I do not have MS Access installed? Reason I ask is because I am getting the following error when attempting to use the Import Wizard in SQL Management Studio to perform this task: "Test connection failed because of an error initializing provider. Cannot start your application. The workgroup information file is missing or opened exclusively by another user." 回答1: If the .mdb file is encrypted with user-level security then you

sp_send_dbmail - formatting row in table as red for an alert

痞子三分冷 提交于 2019-12-01 00:50:30
I'm using something similar to example C on this MSDN page: http://msdn.microsoft.com/en-us/library/ms190307.aspx DECLARE @tableHTML NVARCHAR(MAX) ; SET @tableHTML = N'<H1>Work Order Report</H1>' + N'<table border="1">' + N'<tr><th>Work Order ID</th><th>Product ID</th>' + N'<th>Name</th><th>Order Qty</th><th>Due Date</th>' + N'<th>Expected Revenue</th></tr>' + CAST ( ( SELECT td = wo.WorkOrderID, '', td = p.ProductID, '', td = p.Name, '', td = wo.OrderQty, '', td = wo.DueDate, '', td = (p.ListPrice - p.StandardCost) * wo.OrderQty FROM AdventureWorks.Production.WorkOrder as wo JOIN

how to get name from another table with matching id in another table?

被刻印的时光 ゝ 提交于 2019-12-01 00:21:23
I am using sql server 2008 r2 with php in my website. I have 2 tables. 1 is for employees. (int) (nvarchar) (nvarchar) id name type 1 john 2 2 peter 1 3 leah 2 4 frank 1 5 tang 3 2 is for work (int) (nvarchar) (nvarchar) workid name employees 1 task1 1,3 2 task2 2,3 3 task3 1,3,4 4 task4 2 I want to make query which give me work description with employee name where type < 3. Means i want to get result like this. workid name employee 1 task1 john, leah 2 task2 peter, leah 3 task3 john,leah,frank like wise so how can i achieve this result with sql query ? I can not change in table schema. i

Executing remote procedure with user-defined table type variable parameter

自古美人都是妖i 提交于 2019-11-30 23:05:27
I'm trying to call a remote stored procedure over a linked server. The problem is, one of the required parameters is a user-defined table types. I can't seem to figure out how to declare a local variable as a user-defined table type from a remote server. This is what I'm trying so far, but it doesn't work: DECLARE @tblVar [REMOTESERVER].REMOTEDB.dbo.user_defined_table_type EXEC [REMOTESERVER].REMOTEDB.dbo.procedure_name (@param1 = @tblVar) However the error I'm getting is: The type name 'REMOTESERVER.REMOTEDB.dbo' contains more than the maximum number of prefixes. The maximum is 1. Must

I am unable to use THROW SQL Server 2008 R2

送分小仙女□ 提交于 2019-11-30 21:45:12
问题 SQL Server 2008 R2 Management Studio does not recognized my throw in the below example, it says incorrect syntax near Throw I am trying to throw an error here, so I can handled it in my website when someone insert the same value twice. Begin Try insert into BusinessID (BusinessID) values (@ID) insert into BusinessID (BusinessID) values (@ID) End Try Begin Catch Print 'PK already exist' THROW End Catch 回答1: THROW Statement is introduced in SQL Server 2012 http://msdn.microsoft.com/en-us

Convert NVARCHAR to DATETIME in SQL Server 2008

落花浮王杯 提交于 2019-11-30 21:24:42
In my table LoginDate 2013-08-29 13:55:48 The loginDate column's datatype is nvarchar(150) I want to convert the logindate column into date time format using SQL command Expected result. LoginDate 29-08-2013 13:55:48 DECLARE @chr nvarchar(50) = (SELECT CONVERT(nvarchar(50), GETDATE(), 103)) SELECT @chr chars, CONVERT(date, @chr, 103) date_again SELECT CONVERT(NVARCHAR, LoginDate, 105)+' '+CONVERT(NVARCHAR, LoginDate, 108) AS LoginDate FROM YourTable Output ------------------- 29-08-2013 13:55:48 alter table your_table alter column LoginDate datetime; SQLFiddle demo As your data is nvarchar

SQL Server 2008 R2 Varbinary Max Size

Deadly 提交于 2019-11-30 20:35:33
What is the max size of a file that I can insert using varbinary(max) in SQL Server 2008 R2? I tried to change the max value in the column to more than 8,000 bytes but it won't let me, so I'm guessing the max is 8,000 bytes, but from this article on MSDN , it says that the max storage size is 2^31-1 bytes: varbinary [ ( n | max ) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL