sql-server-2008-r2

How to make SET XACT_ABORT ON rollback the transaction?

跟風遠走 提交于 2020-01-14 08:04:13
问题 Based on the Books Online documentation of SET XACT_ABORT ON, i get the impression that if a T-SQL statement raises a run-time error, the entire transaction is terminated and rolled back: Remarks When SET XACT_ABORT is ON, if a Transact-SQL statement raises a run-time error, the entire transaction is terminated and rolled back. Testing this in SQL Server 2008 R2: SET XACT_ABORT ON; BEGIN TRANSACTION; PRINT 'TranCount befor an error = '+CAST(@@Trancount AS varchar(50)) DROP TABLE QuertyAsdf

Creating procedure SQL Server 2008 R2

坚强是说给别人听的谎言 提交于 2020-01-14 01:40:28
问题 I'm new to SQL, and I'm trying to learn it. I'm creating a procedure to INSERT Members into Member table. Im using this (which ofc works): CREATE PROCEDURE InsertMember AS INSERT INTO Member (FirstName, LastName, City) VALUES ('Blla', 'Blla', 'Blla') But... I want to know if it is possible to create a procedure which when I execute it, to ask user for input. For example: When I execute the procedure it should go like this: @FirstName = 'SOME FIRSTNAME' @LastName = 'SOME LASTNAME' @City =

SQL DateTime Conversion Fails when No Conversion Should be Taking Place

北战南征 提交于 2020-01-13 10:12:15
问题 I'm modifying an existing query for a client, and I've encountered a somewhat baffling issue. Our client uses SQL Server 2008 R2 and the database in question provides the user the ability to specify custom fields for one of its tables by making use of an EAV structure. All of the values stored in this structure are varchar(255) , and several of the fields are intended to store dates. The query in question is being modified to use two of these fields and compare them (one is a start, the other

'insert into' with array

冷暖自知 提交于 2020-01-13 08:37:18
问题 I'm wondering if there's a way to use 'insert into' on a list of values. I'm trying to do this: insert into tblMyTable (Col1, Col2, Col3) values('value1', value2, 'value3') So, what I'm trying to say is that value2 will be an array of strings. I'm going to put this in C# but the SQL statement is all I need really. I know I could just use a foreach and loop through my array but I figured there might be a better way sort of like the SELECT statement here: SQL SELECT * FROM XXX WHERE columnName

Generate Hierarchy value automatically

自古美人都是妖i 提交于 2020-01-13 08:26:30
问题 I have a tree table with column ID , ParentID and Hierarchy and want to generate Hierarchy column value dependent by ParentID . for this purpose I use triggers. do exists better way to generate Hierarchy column value? ALTER TRIGGER [TR_MyTable_BeforInsert] ON [MyTable] INSTEAD OF INSERT AS BEGIN SET NOCOUNT ON; Declare @Name NVarChar(100), @ParentID Int Declare DACategory Cursor For Select A.Name, A.ParentID From Inserted A OPEN DACategory FETCH NEXT FROM DACategory INTO @Name, @ParentID

How does SQL Server determine the order of the columns when you do a `SELECT *`?

…衆ロ難τιáo~ 提交于 2020-01-13 07:59:26
问题 How does SQL Server determine the order of the columns when you do a SELECT * ? I know "Order By" is essential for ordering the data , but I expected the column names to be consistent. Note: My code is not dependent on the actual order the columns are returned. I just want to know how SQL Server decides to order the column names. Of about 20 computers my team is using, one of them behaves differently. Any difference deserves to be investigated. The column name ordering appears to be the same

In OLAP cube wrong Grand Total when attribute is filtered

我的未来我决定 提交于 2020-01-12 14:03:55
问题 A user trying to check the Sales Amount per Salesperson. Sample data: Salesperson Sales Amount 001 1000 002 500 003 750 Grand Total: 2250 It looks fine, but we have the following hierarchy Company > Class > Group > Subgroup in the cube and if a user tries to use this hierarchy in filters - Grand Total fails (if any attribute is unchecked in this hierarchy). Sample: Salesperson Sales Amount 001 1000 002 500 003 750 Grand Total: 350 I've noticed the same problem before when we tried to filter

How to check blocking queries in SQL Server

爷,独闯天下 提交于 2020-01-12 08:09:30
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

How to check blocking queries in SQL Server

末鹿安然 提交于 2020-01-12 08:09:08
问题 I have one warehouse server which got data/sync from legacy system 24/7, I noticed some of my reports/sql jobs performance is uncertain and most of the time I heard from DBA team that my query is blocking to other sync process. From DBA team I came to know command i.e. EXEC SP_WHO2 by which I can identify spid of query which cause blocking by looking into column BlkBy. Please suggest me how I can avoid blocking and other ways to check blocking in SQL Server 回答1: Apart from Sp_Who2 you can use

Database default value is not inserted while create record by entity framework

南笙酒味 提交于 2020-01-12 07:31:13
问题 I have a LoginRecord table in sqlserver 2008 with the following column structure- LoginId - int, identity UserId - int LoginDateTime- Allow nulls false,default value getdate() I am inserting new record by entity framework 6 as below- db.LoginRecords.Add(new LoginRecord() { UserId = UserId }); db.SaveChanges(); But in LoginDateTime table, null value is being inserted. It supposed to be current datetime. I am using database first approach. How can overcome this issue? 回答1: Combined my two