Questions tagged [sql-server-2016]

Use this tag for questions specific to the 2016 version of Microsoft's SQL Server.

Microsoft SQL Server 2016 v.13.0.1601.5 Ready To Manufacture (RTM), was released on June 1, 2016.

There are many editions of SQL Server 2016:

1- Entreprise Edition : Comprehensive, mission-critical in-memory performance with unparalleled security, mission critical high availability, an end-to-end enterprise business intelligence solution with mobile BI built in, in-database advanced analytics at scale, and unlimited virtualization with software assurance. Enterprise edition provides the highest scale and performance for Tier-1 workloads.

2- Standard: Find rich programming capabilities, security innovations, and fast performance for applications and data marts. Easily upgra

3- Developer: Build, test, and demonstrate applications in a non-production environment with this free, full-featured set of SQL Server 2016 SP1 Enterprise edition software.

4- Express: Deploy small databases in production environments with this free, entry-level database that’s ideal for building small, data-driven applications up to 10 GB of disk size.

5- Compact: Free, embedded database app for building ASP.NET websites and Windows desktop applications.

6- Web: Secured, cost effective, and highly scalable data platform for public web sites—available to third-party hosting service providers only.

References

3794 questions
2152
votes
32 answers

How to check if a column exists in a SQL Server table

I need to add a specific column if it does not exist. I have something like the following, but it always returns false: IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'myTableName' AND…
Maciej
  • 21,919
  • 3
  • 20
  • 23
303
votes
2 answers

How do I move a table into a schema in T-SQL

I want to move a table into a specific Schema using T-SQL? I am using SQL Server 2008.
Lukasz
  • 8,710
  • 12
  • 44
  • 72
218
votes
13 answers

SQL Server: Filter output of sp_who2

Under SQL Server, is there an easy way to filter the output of sp_who2? Say I wanted to just show rows for a certain database, for example.
Craig Schwarze
  • 11,367
  • 15
  • 60
  • 80
105
votes
8 answers

Is there a LastIndexOf in SQL Server?

I am trying to parse out a value from a string that involves getting the last index of a string. Currently, I am doing a horrible hack that involves reversing a string: SELECT REVERSE(SUBSTRING(REVERSE(DB_NAME()), 1, CHARINDEX('_',…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
83
votes
2 answers

Why is 199.96 - 0 = 200 in SQL?

I have some clients getting weird bills. I was able to isolate the core problem: SELECT 199.96 - (0.0 * FLOOR(CAST(1.0 AS DECIMAL(19, 4)) * CAST(199.96 AS DECIMAL(19, 4)))) -- 200 what the? SELECT 199.96 - (0.0 * FLOOR(1.0 * CAST(199.96 AS…
Silverdust
  • 1,503
  • 14
  • 26
64
votes
3 answers

SQL Server OPENJSON read nested json

I have some json that I would like to parse in SQL Server 2016. There is a hierarchy structure of Projects->Structures->Properties. I would like to write a query that parses the whole hierarchy but I don't want to specify any elements by index…
Slade
  • 2,311
  • 3
  • 21
  • 25
52
votes
9 answers

SQL to JSON - array of objects to array of values in SQL 2016

SQL 2016 has a new feature which converts data on SQL server to JSON. I am having difficulty in combining array of objects into array of values i.e., EXAMPLE - CREATE TABLE #temp (item_id VARCHAR(256)) INSERT INTO #temp VALUES…
52
votes
1 answer

OPENJSON does not work in SQL Server?

I want to use JSON functions in SQL Server 2016, but when I try to execute OPENJSON function, I get the following error: Msg 208, Level 16, State 1, Line 1 Invalid object name 'openjson'. Why it does not work? I have SQL Server 2016 RC version.
Iva
  • 523
  • 1
  • 4
  • 4
43
votes
5 answers

Create nested JSON arrays using FOR JSON PATH

I need to create a JSON output from a query that uses inner join between two tables with a one to many relationship. I would like the values of the secondary table to be nested as array properties of the primary table. Consider the following…
ATC
  • 907
  • 1
  • 9
  • 14
43
votes
4 answers

How do you OPENJSON on Arrays of Arrays

I have a JSON structure where there are Sections, consisting of multiple Renders, which consist of multiple Fields. How do I do 1 OPENJSON call on the lowest level (Fields) to get all information from there? Here is an example JSON: Declare @layout…
Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174
41
votes
8 answers

SQL Replace multiple different characters in string

I need to replace multiple characters in a string. The result can't contain any '&' or any commas. I currently have: REPLACE(T2.[ShipToCode],'&','and') Which converts & to and, but how do you put multiple values in one line?
coblenski
  • 1,119
  • 2
  • 11
  • 19
39
votes
6 answers

LocalDB parent instance version invalid: MSSQL13E.LOCALDB

I'm unable to add a database on a developer machine. I'm running win 10, visual studio 2015. I re-installed SQL server 2016 twice, last time with firewall disabled it all gave green marks in the end. While i can create databases in VS2015 SQL server…
Peter
  • 2,043
  • 1
  • 21
  • 45
38
votes
5 answers

Get length of json array in SQL Server 2016

You know about the new JSON_ support in SQL Server 2016 so let's say I have this data in a row { "BaseBoarding": 1, "PriceLineStrategy": "PerPersonPerNight", "Currency": "EUR", "BasePriceLineList": [ { "RoomTypeId": 1, …
Mihail Shishkov
  • 14,129
  • 7
  • 48
  • 59
38
votes
8 answers

SQL Select everything after character

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!
coblenski
  • 1,119
  • 2
  • 11
  • 19
30
votes
3 answers

STRING_AGG is not a recognized built-in function name

I've downloaded and installed SQL Server 2016. When I attempted to use the STRING_AGG function I receive this error. Here is my code: SELECT STRING_AGG(cast(FieldNumber AS VARCHAR(100)), ',') FROM Fields I've installed SQL Server 2016 and SP1. Is…
Luke101
  • 63,072
  • 85
  • 231
  • 359
1
2 3
99 100