sql-server-2008-r2

Is there a way to change the values for FixedLenNullInSource and TrimTrailingBlanks?

好久不见. 提交于 2019-12-20 02:31:10
问题 Is there a way to change the values for FixedLenNullInSource and TrimTrailingBlanks ? I use sp_help to compare the output from different servers to see if the tables are identical. FixedLenNullInSource and TrimTrailingBlanks are throwing my comparisons off. 回答1: TrimTrailingBlanks relates to the SET ANSI_PADDING option when the table was created. You might be able to change that without recreating the whole table in a similar way to my answer here for changing the ANSI_NULL option. Otherwise

Is there a way to change the values for FixedLenNullInSource and TrimTrailingBlanks?

ⅰ亾dé卋堺 提交于 2019-12-20 02:31:02
问题 Is there a way to change the values for FixedLenNullInSource and TrimTrailingBlanks ? I use sp_help to compare the output from different servers to see if the tables are identical. FixedLenNullInSource and TrimTrailingBlanks are throwing my comparisons off. 回答1: TrimTrailingBlanks relates to the SET ANSI_PADDING option when the table was created. You might be able to change that without recreating the whole table in a similar way to my answer here for changing the ANSI_NULL option. Otherwise

Escaping ] and ^ characters in a T-SQL “pattern” expression character class

梦想与她 提交于 2019-12-20 02:28:29
问题 I'm trying to emulate Oracle's RTRIM(expression, characters) in MsSql Server 2008 R2 with the following query: REVERSE( SUBSTRING( REVERSE(field), PATINDEX('%[^chars]%', REVERSE(field)), LEN(field) - PATINDEX('%[^chars]%', REVERSE(field)) + 1 ) ) The problem is that I want to be able to trim characters like ] and ^ which do probably need escaping. I don't know how to do this. Things like \] don't work. I'm aware of the ESCAPE clause but I do not understand exactly how it works and, by the way

Calculate forecast average using recursive CTE

白昼怎懂夜的黑 提交于 2019-12-20 02:17:30
问题 I was trying to answer a question here, where I need to calculate a forecast of sales based on the 3 previous months which either can be actuals or forecast. Month Actuals Forecast 1 10 2 15 3 17 4 14.00 5 15.33 6 15.44 7 14.93 Month 4 = (10+15+17)/3 Month 5 = (15+17+14)/3 Month 6 = (17+14+15.33)/3 Month 7 = (14+15.33+15.44)/3 I've been trying to do this using a recursive CTE: ;WITH cte([month],forecast) AS ( SELECT 1,CAST(10 AS DECIMAL(28,2)) UNION ALL SELECT 2,CAST(15 AS DECIMAL(28,2))

Comparing phone numbers sql

萝らか妹 提交于 2019-12-19 21:46:50
问题 I have 2 sets of phone numbers in 2 different tables, table 1 has the straight forward format of 01234567890 and the other table has 3 different formats, sometimes it's 01234567890 or 01234 567890 or 01234-567890 . Currently I'm just doing an Inner join on the tables and only get a few rows returned but would expect more as obviously anything with a hyphen or space will get missed from the join. The way the system is I can't change the data in the table with 3 formats so can't standardise it

TSQL: FOR XML PATH('') Failing To Group

非 Y 不嫁゛ 提交于 2019-12-19 15:25:21
问题 I'm trying to group column values by a specific column using FOR XML PATH('') in TSQL. This is the result in both cases (note that the without XML code - ie: SELECT * FROM @xml - is the same as the with XML code): Class | Animals ================================= Asteroidea | Starfish Mammalia | Dog Mammalia | Cat Mammalia | Coyote Reptilia | Crocodile Reptilia | Lizard According to this article and this article (note that the second article leaves out the GROUP BY , which I'm unsure how the

Auto Increment SQL Value

强颜欢笑 提交于 2019-12-19 12:22:44
问题 In the infinte wisdom of the global DBA at a firm I am working at right now he has created a table that takes an int as an ID field, but does not auto increment the number. I am passing up a table valued parameter from .Net because it has roughly 100 or more rows of data that are being passed up at any one time and I dont want to kill the application, hammer the network or the SQL Server. So this is my stored procedure CREATE PROCEDURE sp_Insert_Supporting_Error_Info (@tvp [dbo].udt_CEQZW

Using NEWID() with CTE to produce random subset of rows produces odd results

纵然是瞬间 提交于 2019-12-19 10:25:06
问题 I'm writing some SQL in a stored procedure to reduce a dataset to a limited random number of rows that I want to report on. The report starts with a Group of Users and a filter is applied to specify the total number of random rows required ( @SampleLimit ). To achieve the desired result, I start by creating a CTE (temp table) with: The top(@SampleLimit) applied group by UserId (as the UserID appears multiple times) order by NEWID() to put the results in a random order SQL: ; with cte_temp as

Is there any way to overcome parameter sniffing in SQL Server?

99封情书 提交于 2019-12-19 08:58:49
问题 I came across parameter sniffing when one of my queries took a much longer time to execute than expected. When I delved a little deeper into this problem I came to know that: When first time query gets executed it (SQL Server) creates execution plan for that query and for other n number of times same query executed and if it has large variance in result set with first time execution then parameter sniffing problem occurs". This was in my scenario. Now my question is, is there any way or

Transaction context in use by another session

北慕城南 提交于 2019-12-19 05:19:26
问题 I have a table called MyTable on which I have defined a trigger, like so: CREATE TRIGGER dbo.trg_Ins_MyTable ON dbo.MyTable FOR INSERT AS BEGIN SET NOCOUNT ON; insert SomeLinkedSrv.Catalog.dbo.OtherTable (MyTableId, IsProcessing, ModifiedOn) values (-1, 0, GETUTCDATE()) END GO Whenever I try to insert a row in MyTable , I get this error message: Msg 3910, Level 16, State 2, Line 1 Transaction context in use by another session. I have SomeLinkedSrv properly defined as a linked server (for