sql-server-2016

Error while using SSMS 2016 : Object cannot be cast from DBNull to other types

五迷三道 提交于 2019-12-09 19:17:35
问题 Can anyone resolve this issue: SQL Server Management Studio 2016 CTP3 (13.0.900.73) on a Windows 10 Laptop Object Explorer > Server > Databases > Database Right Click - Properties Instead of getting the Database Properties dialogue box I instead get this pop-up: TITLE: Microsoft SQL Server Management Studio Cannot show requested dialog. ADDITIONAL INFORMATION: Cannot show requested dialog. (SqlMgmt) Object cannot be cast from DBNull to other types. (mscorlib) BUTTONS: OK Edit: Issue is

SQL Select everything after character

南笙酒味 提交于 2019-12-09 18:18:47
问题 I'd like to select everything AFTER a certain character (-) that is placed on the most right side. Eg. abcd-efgh-XXXX And I'd like to select the XXXX part Thanks! 回答1: You can use: select right(col, charindex('-', reverse(col)) - 1) 回答2: DECLARE @x varchar(100) SET @x = 'abcd-efgh-XXXX' SELECT RIGHT(@x, CHARINDEX('-', REVERSE(@x)) - 1) 回答3: Using string split available from SQLServer 2016 ;with cte as ( select *,row_number() over (order by (select null)) as rownum from string_split('abcd-efgh

Why does the FOR Clause not work with an alias in SQL Server 2016 with temporal tables?

爷,独闯天下 提交于 2019-12-08 19:47:36
问题 I have a SQL Server 2016 database with temporal tables. One temporal table is called Company. I am trying to query it to get current records and all historical records. I first tried the following query: select * from Company c FOR SYSTEM_TIME all and got the following error: Incorrect syntax near 'FOR'. However, if I try it without the alias it works fine: select * from Company FOR SYSTEM_TIME all I could not find any documentation about this- is it a legitimate constraint, a known issue, or

Incorrect syntax near format in BULK INSERT?

偶尔善良 提交于 2019-12-08 17:45:17
问题 I'm trying to figure out why the BULK INSERT command I'm using isn't recognizing the FORMAT and FIELDQUOTE options used in the command. BULK INSERT dbo.tblM2016_RAW_Current_Import_File FROM '\\x\tms\SCADA.dat' WITH ( FIRSTROW = 1, FORMAT = 'CSV', FIELDQUOTE = '"', FIELDTERMINATOR = '\t', ROWTERMINATOR = '\n' ) For some reason, I'm getting the error: Msg 102, Level 15, State 1, Line 6 Incorrect syntax near 'FORMAT'. Addition : FORMAT shows up in pink text in SSMS, FIELDQUOTE shows in black

What is the best way to query deleted records with SQL Server 2016 temporal tables?

半城伤御伤魂 提交于 2019-12-08 17:35:50
问题 I'm looking at SQL Server 2016 temporal tables and can't find any efficient way to query for all historical records that are now deleted. I prefer not to soft-delete or moving to a 'deleted items table', as I feel with temporal tables it is redundant. Can this can be achieved with temporal tables in an efficient way? 回答1: Temporal tables are intended to give you a point-in-time view of your data, not a state view - it doesn't actually understand state. Nothing is exposed to users to determine

Handling objects being different for different SQL Server Versions

安稳与你 提交于 2019-12-08 08:46:26
I have created a new database project in Visual Studio and have been adding my pre-existing objects to it. This is a database that we'll be deploying to multiple different servers with at least two different versions of sql server. I have a view that looks at availability groups and pulls the Is_Distributed column if the server is 2016. I need a way in this project to essentially save both versions, the 2014 and 2016, and be able to potentially deploy the correct version depending on what server i'm deploying to. Is this possible to do in a Database Project in Visual Studios? One solution

Handling objects being different for different SQL Server Versions

左心房为你撑大大i 提交于 2019-12-08 08:37:02
问题 I have created a new database project in Visual Studio and have been adding my pre-existing objects to it. This is a database that we'll be deploying to multiple different servers with at least two different versions of sql server. I have a view that looks at availability groups and pulls the Is_Distributed column if the server is 2016. I need a way in this project to essentially save both versions, the 2014 and 2016, and be able to potentially deploy the correct version depending on what

Error when inserting into temporal table using Entity Framework Core 2.1

断了今生、忘了曾经 提交于 2019-12-08 02:27:03
问题 I'm getting the below error when trying to insert into a temporal table using Entity Framework Core 2.1. Cannot insert an explicit value into a GENERATED ALWAYS column in table 'db_test.dbo.Department'. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column. Below is my table schema CREATE TABLE Department ( DeptID int NOT NULL PRIMARY KEY CLUSTERED, DeptName varchar(50) NOT NULL, ManagerID INT NULL, ParentDeptID int NULL,

Delete an object from nested array in openjson SQL Server 2016

久未见 提交于 2019-12-07 15:10:22
问题 I want to delete the "AttributeName" : "Manufacturer" from the below json in SQL Server 2016: declare @json nvarchar(max) = '[{"Type":"G","GroupBy":[], "Attributes":[{"AttributeName":"Class Designation / Compressive Strength"},{"AttributeName":"Size"},{"AttributeName":"Manufacturer"}]}]' This is the query I tried which is not working select JSON_MODIFY(( select JSON_Query(@json, '$[0].Attributes') as res),'$.AttributeName.Manufacturer', null) 回答1: Here is the working solution using the for

SSRS Mobile Reporting Not Supported

对着背影说爱祢 提交于 2019-12-07 13:35:54
问题 I am trying to test out the new SSRS 2016 features, here's what I have so far: Signed up for an Azure trial Installed a SQL Server 2016 VM Created a DB Configured the reporting services to run classic reports Downloaded the Mobile Report Publisher I have been trying stuff out using the predetermined data, however I wanted to pull in some data I'm familiar with. When I try to connect to the server (localhost/reports) I get a Server Error as the 'Server does not support mobile reports'. Is