sql-server-2012

JSON_VALUE for SQL Server 2012?

三世轮回 提交于 2020-08-08 07:53:09
问题 I want to extract values from a JSON string in SQL. Started to write a function to do so but then I thought "surely someone else has already done this?". I was super excited when I saw there is a JSON_VALUE function in SQL Server now... but then sorely disappointed when I realized it wasn't added until 2016. :( So... I am in the middle of writing my own version of this function. I'm certain it will seem to work at first, and then I will get errors occasionally until I perfect it over time.

SQL Server 2012 Read Only Connection

旧街凉风 提交于 2020-07-30 02:43:12
问题 How can I setup a read only connection to sql server 2012 without the need to create a read only user? 回答1: Connection String property ApplicationIntent From the docs: Declares the application workload type when connecting to a server. Possible values are ReadOnly and ReadWrite. For example: ApplicationIntent=ReadOnly 来源: https://stackoverflow.com/questions/14883380/sql-server-2012-read-only-connection

SQL Server 2012 Read Only Connection

感情迁移 提交于 2020-07-30 02:42:48
问题 How can I setup a read only connection to sql server 2012 without the need to create a read only user? 回答1: Connection String property ApplicationIntent From the docs: Declares the application workload type when connecting to a server. Possible values are ReadOnly and ReadWrite. For example: ApplicationIntent=ReadOnly 来源: https://stackoverflow.com/questions/14883380/sql-server-2012-read-only-connection

Is there a function like isdate() for datetime2?

送分小仙女□ 提交于 2020-07-20 07:46:14
问题 I know there is a function called ISDATE to validate DATETIME columns, but it works only for the SMALLDATETIME and DATETIME types. Is there a similar way to validate the new data type DATETIME2 in SQL Server 2008 and 2012? 回答1: In SQL Server 2012, you can use TRY_CONVERT : SELECT TRY_CONVERT(DATETIME2, '2012-02-02 13:42:55.2323623'), TRY_CONVERT(DATETIME2, '2012-02-31 13:42:55.2323623'); Results: 2012-02-02 13:42:55.2323623 NULL Or TRY_PARSE : SELECT TRY_PARSE('2012-02-02 13:42:55.2323623' AS

SQL Server DATEDIFF Computed Column Between Rows

折月煮酒 提交于 2020-07-09 04:43:49
问题 I currently have a table similar to this - RecordTime Running Fault ----------------------------------------------- 2016-09-15 11:32:01.00 0 202 2016-09-15 11:32:08.00 1 202 2016-09-15 11:39:31.00 0 21 2016-09-15 11:40:07.00 1 4 2016-09-15 11:42:11.00 0 21 2016-09-15 11:42:39.00 1 45 I then wanted to calculate the time difference between the RecordTimes for each record. For this I am using the following - WITH rows AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY RecordTime) AS rn FROM dbo.Table1 )

hide a column from table in MS SQL Server

空扰寡人 提交于 2020-06-25 03:35:07
问题 Can anyone please share the steps to hide the particular column from the table in SQL Server 2012 as I don't want to delete that column By hide I mean that whenever I use the select query against that particular table it should never show me that column. Is it possible? I need to make the column as hidden irrespective of any user login and whatever query i use 3rd party edit Based on the comment But the problem is whenever i open the table in sql i dont want to see that particular column i

(SQL) Identify positions of multiple occurrences of a string format within a field

纵然是瞬间 提交于 2020-06-17 02:30:18
问题 I need to split a narrative field (free text) into multiple rows. Format is currently along the lines of: Case_Reference | Narrative ```````````````|````````````````````````````````````` XXXX/XX-123456 | [Endless_Text up to ~50k characters] Within the narrative field as text, individual entries (when various agents have done something to the case) begin with the entry date followed by two spaces (i.e. 'dd/mm/yyyy ' ), with the values of the dates changing with each entry within that same

Best ANSI options when creating a new database

﹥>﹥吖頭↗ 提交于 2020-05-15 04:40:06
问题 I'm in the process of creating a new database onto SQL Server 2012 for our production environment. When I use the "New Database..." option from SQL Server Management Studio and generate the output I get: CREATE DATABASE [AAA] CONTAINMENT = NONE ON PRIMARY ( NAME = N'AAA', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQL2014\MSSQL\DATA\AAA.mdf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'AAA_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12

Count instances of multiple invoices and pivot on location

老子叫甜甜 提交于 2020-04-30 12:23:33
问题 The embarassing fiddle for the entire question can be found here. Basically I have three tables containing invoice information: CREATE TABLE billing ([bill_id] varchar(5), [bill_reference_id] varchar(8), [bill_date] date, [billing_type] varchar(1)) CREATE TABLE billing_detail ([bill_id] varchar(5), [accpac_category_type] varchar(1), [location_id] varchar(1)) CREATE TABLE locations ([location_id] varchar(1), [location] varchar(50)) ; Invoices can have two billing_types I and C (invoice and

Count instances of multiple invoices and pivot on location

假如想象 提交于 2020-04-30 12:22:11
问题 The embarassing fiddle for the entire question can be found here. Basically I have three tables containing invoice information: CREATE TABLE billing ([bill_id] varchar(5), [bill_reference_id] varchar(8), [bill_date] date, [billing_type] varchar(1)) CREATE TABLE billing_detail ([bill_id] varchar(5), [accpac_category_type] varchar(1), [location_id] varchar(1)) CREATE TABLE locations ([location_id] varchar(1), [location] varchar(50)) ; Invoices can have two billing_types I and C (invoice and