sql-server-2016

How to JSON_MODIFY on Array of Array?

可紊 提交于 2019-12-12 18:26:51
问题 My strucutre look like this Declare @layout NVARCHAR(MAX) = N' { "Sections": [ { "SectionName":"Section1", "SectionOrder":1, "Renders":[ { "RenderName":"Render1", "RenderOrder":1, "Fields":[ { "FieldName":"Field1", "FieldData":"Data1" }, { "FieldName":"Field2", "FieldData":"Data2" } ] }, { "RenderName":"Render2", "RenderOrder":2, "Fields":[ { "FieldName":"Field1", "FieldData":"Data1" }, { "FieldName":"Field2", "FieldData":"Data2" } ] } ] }, { "SectionName":"Section2", "SectionOrder":2,

Enable XA transactions for MSSQL Server docker image

六眼飞鱼酱① 提交于 2019-12-12 18:25:35
问题 I have MSSQL Server Linux docker image that I use for development and I need to enable XA transactions on this instance, I search a lot but all the tutorials I found show only how to do that from a windows machine, no Linux. So How to enable XA transactions from command line, or is there a configuration file for that. 回答1: In SQLServer 2016 and 2017 for Linux it is not possible to use XA transactions. Starting with SqlServer 2019 for Linux (In preview at the time of writing), distributed

DATEDIFF SQL Server 2016 JSON

試著忘記壹切 提交于 2019-12-12 15:12:21
问题 Currently have a startDate and EndDate formatted in JSON and trying to use a DATEDIFF function to work out the year difference using OPENJSON. I am currently trying the below DECLARE @Json VARCHAR(4000) = ' { "Name": "bob", "StartDate": "12/02/2015", "EndDate": "12/02/2016" }'; SELECT Name , StartDate , EndDate FROM OPENJSON(@Json, '$') WITH (Name VARCHAR(50), StartDate DATETIME2, EndDate DATETIME2 ,DATEDIFF(YEAR, StartDate DATETIME2, EndDate DATETIME2) INT AS Duration ) WHERE Name = 'bob'

Get a count based on the row order

橙三吉。 提交于 2019-12-12 15:08:31
问题 I have a table with this structure Create Table Example ( [order] INT, [typeID] INT ) With this data: order|type 1 7 2 11 3 11 4 18 5 5 6 19 7 5 8 5 9 3 10 11 11 11 12 3 I need to get the count of each type based on the order, something like: type|count 7 1 11 **2** 18 1 5 1 19 1 5 **2** 3 1 11 **2** 3 1 Context Lets say that this table is about houses, so I have a list houses in an order. So I have Order 1: A red house 2: A white house 3: A white house 4: A red house 5: A blue house 6: A

What can I use in a SQL query to help me determine why my query is not returning any data results

こ雲淡風輕ζ 提交于 2019-12-12 14:19:29
问题 Can someone assist me in troubleshooting my SQL query to discover why it's not returning any results, only the column aliases? I've broken it apart, and all sections that obviously group together returns the expected data individually. Thanks for any guidance/assistance in advance. Below is my script: ... DECLARE @u_cnt INT; DECLARE @f_yr DATE; DECLARE @qrt VARCHAR(3); DECLARE @dnum VARCHAR(5); SET @u_cnt = 10000; SET @f_yr = '2002-05-20'; SET @qrt = 'Q2'; SET @dnum = '43234'; SELECT c

Edit a dtsx through SSMS

╄→гoц情女王★ 提交于 2019-12-12 12:07:28
问题 I created and executed a dtsx with SSMS corresponding wizard: This was to import a flat file in an existing table. At the end I saved the "package" as a .dtsx file Now I need to modify the column mappings and re-execute this package. Is there any way I can do it, using SQL Server Management Studio? I tried opening the file, but it opens this dialog: Where I cannot edit the mappings any more. Update: I understand that "editing" a dtsx is not a simple thing, yet is there a reason why the wizard

How to select all parameter values in SSRS?

一个人想着一个人 提交于 2019-12-12 05:49:41
问题 I have a parameters @Year and @Month in my report, where month has assigned values like January(label): 1(values), February: 2, ... My datased is feeded by stored procedure which has a filter WHERE (cal.CalendarYear = @Year) AND (cal.MonthId = @Month) When I check 'Allow multiply values' in parameter settings, it returns an error Error converting data type nvarchar into int. How can I select all values (by default)? 回答1: If you don't need to use a Stored Proc you can easily solve the problem.

SQL Server Temporal Table Creating Duplicate Records

点点圈 提交于 2019-12-12 04:48:15
问题 I have implemented a system versioned (temporal) table on one of our production tables that is frequently updated. This table is updated by applications, power users (manually with custom scripts and standardized sprocs), and system jobs. I have just run into a situation where I see a new record inserted into the history table but it appears exactly the same as the one before it. As I research this I see it is not a one off situation; there are many more. Please keep in mind the begin and end

Subquery returned more than 1 value. (Insert within a while loop)

♀尐吖头ヾ 提交于 2019-12-12 02:19:13
问题 DECLARE @int int DECLARE @saveamount int DECLARE @savedate datetime SET @int=1 SET @saveamount=400 SET @savedate= '20160101 13:00:00.00' WHILE @int<=357 BEGIN INSERT INTO watersave (reservoirid, amount, savedate) VALUES (1,@saveamount,@savedate) SET @int=@int+1 SET @saveamount=@saveamount+(SELECT ROUND((6 - 12 * RAND()), 0)) SET @savedate=@savedate+1 END Trying to insert for test purposes but stacked with the subquery returned more than 1 value error on line 9. Any idea? Regards 回答1: Since

Daily snapshot table using cte loop

眉间皱痕 提交于 2019-12-11 17:24:32
问题 I need daily snapshot of how many employees are employed on any given day (defined as @date between Start_Date & End_Date), with one line per date. At one point, the below script would return all daily snapshots, but they were each returned within a separate results window. I couldn't get the query to combine all results to insert each new result into #PLEASEWORK . I need to get the below to work for two consecutive days. It uses int dates. I have inherited this problem and am building a date