sql-server-2012

SQL Server describing first result set fails when temp table is used (sp_describe_first_result_set)

对着背影说爱祢 提交于 2019-12-10 17:14:39
问题 Long story short, I have a third-party application which behaves differently when it cannot retrieve the metadata of the query/stored procedure. It is known, that sys.sp_describe_first_result_set fails to retrieve the metadata for a stored procedure when a temp table is used in it. For the sake of simplicity, here is a simple example. CREATE PROCEDURE dbo.Test @Seed INT = 0 AS BEGIN CREATE TABLE #MyTemp ( ID INT NOT NULL ); INSERT INTO #MyTemp (ID) VALUES (@Seed + 1) , (@Seed + 2) , (@Seed +

How can SQL Server 2012 (or SSIS) notify NServiceBus upon completion of a task?

我与影子孤独终老i 提交于 2019-12-10 16:44:39
问题 We have some very long running ETL packages (some run for hours) that need to be kicked off by NServiceBus endpoints. We do not need to keep a single transaction alive for the entire process, and can break it up into smaller transactions. Since an NServiceBus handler will wrap itself in a transaction for the entirety, we do not want to handle this in a single transaction because it will time out--let alone create issues with locking in the DBMS. My current thoughts are that we could spawn

SQL Server 2012 Import CSV to mapped Columns

蹲街弑〆低调 提交于 2019-12-10 16:38:39
问题 I'm currently trying to import about 10000 rows (from a CSV file) into an existing table. I only have 1 column which I'm trying to import, but in my table I have a another column called TypeId which I need to set to a static value i.e. 99E05902-1F68-4B1A-BC66-A143BFF19E37 . So I need something like INSERT INTO TABLE ([Name], [TypeId]) Values (@Name (CSV value), "99E05902-1F68-4B1A-BC66-A143BFF19E37") Any examples would be great. Thanks 回答1: As mentioned above import the data into a temporary

UPDATE + WITH (ROWLOCK) + CTE

耗尽温柔 提交于 2019-12-10 16:32:10
问题 I can't find any documentation about syntax for T-SQL statement: I need to make an WITH (ROWLOCK) UPDATE on a CTE result. Something like: (so updated will be top1000 table1.col2. Statement WITH (ROWLOCK) during an UPDATE on rows of table1 is crucial) ;WITH CTE AS ( SELECT TOP(1000) table1.col2 FROM table1 INNER JOIN table2 ON table1.id = table2.id ) UPDATE CTE WITH (ROWLOCK) SET col2 = 1 The above statement is probably syntactically correct, however if someone will find such example, please

SQL Server generating random spatial geography around point?

╄→гoц情女王★ 提交于 2019-12-10 16:16:43
问题 I have several thousand records in a development environment, each associated with a centroid of a particular zip code. For testing purposes, I need to randomly scatter each SQL Server geography point 0-5 miles around that centroid. So in the example below I want to update LocationGeo so it is 0-5 miles away from its respective ZipGeo. Do I have to use a random % applied to each Lon/Lat or is there a better option? LocationID int LocationGeo geography ZipCode char(5) ZipCode char(5) ZipGeo

Protection level changed mid project - now project won't build

吃可爱长大的小学妹 提交于 2019-12-10 15:52:59
问题 Started a new SSIS project, and forgot to set the default protection level to "Don't save sensitive" (our standard) Now midway through the project and made the changes (at project level and in each package.) When checked all packages are Don't Save Sensitive and the project is Don't Save Sensitive, however when attempting a build, I get Project consistency check failed. The following inconsistencies were detected: PACKAGE1.dtsx has a different ProtectionLevel than the project. PACKAGE2.dtsx

SQL Server XQuery returns an error

情到浓时终转凉″ 提交于 2019-12-10 15:49:09
问题 I am performing a query against an XML data type column in SQL Server 2012. An example of the data is: <ns:Resume xmlns:ns="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"> <ns:Name> <ns:Name.Prefix></ns:Name.Prefix> <ns:Name.First>Shai</ns:Name.First> <ns:Name.Middle></ns:Name.Middle> <ns:Name.Last>Bassli</ns:Name.Last> <ns:Name.Suffix></ns:Name.Suffix> </ns:Name> ... </ns:Resume> I am trying to write a query to return the first names. This query returns a list of

How to convert CURSOR based query in to SET based

吃可爱长大的小学妹 提交于 2019-12-10 15:17:03
问题 I'm not a expert on SQL and I'm working on a huge SQL code and unfortunately it has a CURSOR which handles another two nested CURSORS within it (totally three cursors inside a stored procedure), which handles millions of data to be DELETE,UPDATE and INSERT. This takes a whole lot of time (more than 13 hrs and eventually gets an error 'cursor names datasets already exists') because of row by row execution and I'm trying to modify this in to SET based approach and I'm stuck how to do the INSERT

How could a INNER/RIGHT/LEFT JOIN be 14x slower than a FULL JOIN?

旧城冷巷雨未停 提交于 2019-12-10 14:49:59
问题 I have a query that takes 2.5 seconds with FULL JOIN, and 40 seconds with INNER, RIGHT or LEFT JOIN. Here is the query. The subquery (done twice) only takes 1.3 seconds on its own. SELECT T1.[time], T1.Total, T1.rn, T2.[time], T2.Total, T2.rn FROM ( select [time], MAX(ComputedValue) as Total, row_number() over (order by [time]) as rn FROM ( select SUBSTRING(CONVERT(CHAR(10), IntervalStartTime, 108), 0, 6) as [time], ComputedValue from LoadTestTransactionSample where LoadTestRunId=285 and

how to replace second position string with new in sql server

扶醉桌前 提交于 2019-12-10 14:42:21
问题 I have one question: in sql server, how to replace the 2nd occurrence of the string happy to the string new , otherwise keep as it is(same). Table: CREATE TABLE [dbo].[stringrep]( [name] [varchar](100) NULL, [id] [int] NULL ) INSERT [dbo].[stringrep] ([name], [id]) VALUES (N'happy happy year', 1) GO INSERT [dbo].[stringrep] ([name], [id]) VALUES (N'very happy new year', 2) GO INSERT [dbo].[stringrep] ([name], [id]) VALUES (N'happy new year hello', 3) GO INSERT [dbo].[stringrep] ([name], [id])