sql-server-2012

Comparing current Month and previous Month's rows on a column, SQL Server 2012

限于喜欢 提交于 2019-12-08 21:55:57
问题 I need some guidance and help with a question I am not entirely sure how to solve in SQL Server 2012. I think LAG and LEAD functions could be useful but I am not sure. This is what my data looks right now: ========================================= YearMonth LocationCode Active ========================================= 201405 123 0 201406 123 2 201409 211 1 201410 211 0 201411 214 0 201412 214 3 We have a YearMonth column that shows how the status looked like for each locationCode and an

How to setup weekly auto backup in SQL Server 2012?

我只是一个虾纸丫 提交于 2019-12-08 18:33:22
问题 Please advice how can i setup automated database backup in my SQL Server 2012. I need to take all databases (currently it contains only 3 ) in SQL server an automated weekly backup which runs on Every Friday at 0100 h (1 AM). These back up files (*.bak) should be placed in E:\Backups folder. 回答1: In Microsoft SQL Server Management Studio , open the Object Explorer and then: Right-clic on Management > Maintenance Plans Clic on New Maintenance Plan... Give a name to your plan Create as many

In SQLServer 2012 TSQL, what's the difference of using XML RAW, XML AUTO and XML PATH

百般思念 提交于 2019-12-08 17:24:30
问题 As the title, all open minds are welcomed I tested in my computer, the output seems to be the same. For example. USE BOB_DATABASE SELECT ID, Name, First_Name, Last_Name FROM DBO.T_User FOR XML AUTO USE BOB_DATABASE SELECT ID, Name, First_Name, Last_Name FROM DBO.T_User FOR XML RAW USE BOB_DATABASE SELECT ID, Name, First_Name, Last_Name FROM DBO.T_User FOR XML RAW, ELEMENTS USE BOB_DATABASE SELECT ID, Name, First_Name, Last_Name FROM DBO.T_User FOR XML PATH('CUSTOMERS') 回答1: XML RAW : each row

Wrong connection string NHibernate 3.3

狂风中的少年 提交于 2019-12-08 17:11:48
问题 How to write correct connection string for Nhibernate using SQL Server 2012? Should I write also database name? Error: I get error with wrong „initial catalog” Wrong connection string for NHibernate (I copy this connection string from my server): <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="dialect"

CONVERT issue in sqlserver with Msg 529 error

谁都会走 提交于 2019-12-08 17:02:29
select CONVERT(datetime,value,103) from results This statement is giving me a error "Msg 529, Level 16, State 2, Line 1 Explicit conversion from data type text to datetime is not allowed." VALUE column Datatype is TEXT in the RESULTS table. How can i overcome the above problem. please help ! You can't convert from text to datetime You must apply two convert operations. The first: From text to varchar The second: From varchar to datetime So your query will become: SELECT CONVERT(datetime, CONVERT(varchar(30),value), 103) FROM results Plus: text datatype is deprecated for new versions of Sql

How to remove auto increment from table in sql server 2012

守給你的承諾、 提交于 2019-12-08 16:38:05
问题 I have created a table in SQL Server 2012 with primary key as auto increment. But how can I remove that auto increment property from the table using a SQL query? 回答1: If you need to keep the data in that column then create a new column on the table which is of the same type (but a different name), copy the data from the column you want to get rid of to the new one, drop the old column and rename the new. Complete example: CREATE TABLE test(col1 INT IDENTITY (1,1) NOT NULL, col2 VARCHAR(10)

SQL Server decimal variable assignment?

此生再无相见时 提交于 2019-12-08 16:29:24
问题 I'm trying to write a stored procedure and I'm getting unexpected divide by 0 exceptions. I've narrowed it down to the following example. Why in the world does this : declare @A decimal; declare @B decimal; declare @C decimal; set @A = 4; set @B = 9; set @C = @A/@B select @A/@B as 'Expected' select @C as 'Wut' result in this? Expected --------------------------------------- 0.4444444444444444444 (1 row(s) affected) Wut --------------------------------------- 0 (1 row(s) affected) 回答1: The

Entity Framework and SQL Server 2012 Paging

做~自己de王妃 提交于 2019-12-08 16:05:03
问题 SQL Server 2012 introduces a more efficient mechanism for paging using FETCH and OFFSET which could have a big impact on performance of apps which use a lot of paging. Does Entity Framework 5 support this? So if Im using EF to page using Take + Skip will the LINQ queries be translated into the new 2012 TSQL if EF is targeting SQL Server 2012? 回答1: EF 5 doesn't support this feature - actually I think none of SQL Serve 2012 features is available in EF. You can vote for this feature on Data

Problems creating a full text index on a view

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 15:55:55
问题 I have a view which has been created like this: CREATE VIEW [dbo].[vwData] WITH SCHEMABINDING AS SELECT [DataField1] , [DataField2] , [DataField3] FROM dbo.tblData When I try to create a full text index on it, like this: CREATE FULLTEXT INDEX ON [dbo].[vwData]( [DataField] LANGUAGE [English]) KEY INDEX [idx_DataField]ON ([ft_cat_Server], FILEGROUP [PRIMARY]) WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM) I get this error: View 'dbo.vwData' is not an indexed view. Full-text index is not

Why would SQL Server's SET DEADLOCK_PRIORITY HIGH not be honored?

末鹿安然 提交于 2019-12-08 15:48:26
问题 I've captured a SQL Server 2012 deadlock graph (using Gail Shaw's query) that shows a process with taskpriority="10" being picked as the deadlock victim over 2 processes with taskpriority="0". My understanding is that the deadlock priority is checked first and lower priority processes will be chosen as the victim. Only when all processes are equal priority will other factors be relevant. Can anyone shed any light on why DEADLOCK_PRIORITY might not be honored? Interestingly, the SET DEADLOCK