sql-server-2012

SQL - Create XML - How to set Unicode UTF-8

人盡茶涼 提交于 2019-12-11 04:34:04
问题 I have a problem with creating an XML file from inside a SQL PROCEDURE. The XMLs get created and placed in the correct folder. Although when I open the file in XMLSpy, it says the following error: Your file contains 3 character(s) that should not be present in a file using the Unicode UTF-8 encoding... The offending characters are è (0xE8), ü (0xFC), é (0xE9) When I open the XML file in Notepad++ and check for encoding (via menu Encoding on top), it says it is in ANSI and not in UTF-8. So my

Combine multiple html rows into one

╄→尐↘猪︶ㄣ 提交于 2019-12-11 04:22:16
问题 I am using SQL Server 2012 and I have the following two tables Blog Id Title 1 My Blog Title BlogContent Id Blogid Content 1 1 <p>My First Paragraph</p> 2 1 <p>My Second Paragraph</p> Each Blog Entry may have multiple Content entries. This is a varchar field that contains HTML content. I need to select a blog and all of its content combined together. here is what I tried: SELECT B.Id, B.Title, STUFF(( SELECT '' + BC.Content FROM BlogContent BC WHERE B.Id = BC.Blogid ORDER BY BC.Id ASC OFFSET

Split string via select statement

眉间皱痕 提交于 2019-12-11 04:21:11
问题 Fairly simple question, but seems impossibe to get an answer. If I have this: declare @Agent nvarchar(4000) = '2131235,334225'; Is there a select statement I can write to split the string where the coma is, WITHOUT having to write a function? Something like: SELECT SOME_SPLIT_LOGIC(@Agent) I would like it to return: Column -------- 2131235 334225 Please note I am use MS-SQL 2012 回答1: DECLARE @LeftPart TABLE (Agent int ) DECLARE @RightPart TABLE (Agent1 int ) declare @Agent nvarchar(4000) =

Optimizing a SQL Query which is already doing an index seek

做~自己de王妃 提交于 2019-12-11 04:13:47
问题 I have a SQL query which is pretty efficient, but I have a feeling it can be improved upon. It's the 48% cost on the sort after the index seek using IX_thing_time_location that I would hope can be improved upon. I would hate to think that this is the best that can be done with this query. Is there anything else I can do to improve performance in terms of updating the query, changing my indexes, partitioning (I know these doesn't always mean performance gains)? Here is the execution plan: http

SQL Server 2012 Insert DATEDIFF into column trigger whenever a new record is inserted

拥有回忆 提交于 2019-12-11 04:08:51
问题 Table CREATE TABLE CurrentApplication ( StartDate datetime NOT NULL, EndDate datetime NOT NULL, NoOfDays integer, StaffID integer NOT NULL, AppStatus varchar(30) NOT NULL DEFAULT 'PENDING' ) Trigger CREATE TRIGGER InsertNoOfDays ON CurrentApplication AFTER INSERT AS BEGIN DECLARE @temp INT SELECT @temp = DATEDIFF(day, EndDate, StartDate) FROM inserted INSERT INTO CurrentApplication(NoOfDays) VALUES (@temp) --SELECT StaffID = inserted.StaffID --FROM inserted -- INSERT INTO CurrentApplication

SQL Server Management studio won't start - Type library could not be found

这一生的挚爱 提交于 2019-12-11 04:01:58
问题 I am running SQL Server Management Studio Developer Edition 2012, and the program would not start this morning. I have tried everything online, but to no avail. When I (attempt to) start the application, i am greeted with a message: "The proper type library could not be found in the system registry An attempt to repair this condition failed because you do not have the permissions to write tot he system registry or because thetype library could not be loaded" If i click "ok" on this message,

Insert Statement

烂漫一生 提交于 2019-12-11 03:47:36
问题 I want to insert the values ('testu', 'testp', 'testname', 'testsur', 'testemail') into [dbo].[users] I'm using Microsoft SQL Server 2012 and anytime i try to query something like INSERT INTO [dbo].[users] VALUES ('testu', 'testp', 'testname', 'testsur', 'testemail') I get an Error on the "INSERT" statement saying: This statement is not recognized in the context. What does this mean? How can i fix it? CREATE TABLE [dbo].[users] ( [username] VARCHAR (40) NOT NULL, [password] VARCHAR (40) NOT

LAST_VALUE in SQL Server 2012 is returning weird results

做~自己de王妃 提交于 2019-12-11 03:38:24
问题 I am having a weird result when I am trying to get the LAST_VALUE from a table in SQL Server 2012. This is the table I have PK | Id1 | Id2 1 | 2 | 5 2 | 2 | 6 3 | 2 | 5 4 | 2 | 6 This is my query SELECT Id1, Id2, LAST_VALUE(PK) OVER (PARTITION BY Id1 ORDER BY Id2) AS LastValue FROM @Data This is the result I am expecting Id1 | Id2 | LastValue 2 | 5 | 3 2 | 5 | 3 2 | 6 | 4 2 | 6 | 4 This is what I am receiving Id1 | Id2 | LastValue 2 | 5 | 3 2 | 5 | 3 2 | 6 | 2 2 | 6 | 2 Here is a

pyodbc doesn't report sql server error

邮差的信 提交于 2019-12-11 03:32:38
问题 I have an issue where pyodbc doesn't capture errors returned from stored procedure. My actual stored proc does a lot of stuff but for the purpose of demonstrating the error I created a simple proc and associated python code. Relevant code is below: Stored Procedure: CREATE PROCEDURE [dbo].[testErrors] -- Add the parameters for the stored procedure here AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements

Locking database on SELECT INTO

人盡茶涼 提交于 2019-12-11 03:19:59
问题 I have a query that return a huge number of rows and I am using SELECT INTO (instead of INSERT INTO ) to avoid having problems with transaction log. The problem is: while this query is running, I can read objects but not showing them in object explorer. When I try to expand the tables item, for example, I receive the message bellow: Is there a way to avoid this problem? 回答1: Now here is a Test for you which will give answer to your question... Open a Query window in SSMS. Write any query