sql-server-2016

A concatenation OPENJSON in a SQL Server 2016 stored procedure

做~自己de王妃 提交于 2019-12-11 06:04:53
问题 I need to combine all of the authors for a particular UID. The basic fields are working from the code at another post. DECLARE @json NVARCHAR(MAX) SET @json = '{ "header": { "type": "esummary", "version": "0.3" }, "result": { "uids": [ "17784783", "19505939", "30166592" ], "17784783": { "uid": "17784783", "pubdate": "2007 Aug", "epubdate": "2007 Jul 20", "source": "PLoS Comput Biol", "sortpubdate": "2007/08/01 00:00", "authors": [ { "name": "Yu Y", "authtype": "Author", "clusterid": "" }, {

On creating a table column of type “float with precision” column gets created as “real” type in SQL server

南笙酒味 提交于 2019-12-11 05:14:54
问题 I created a simple table as below: create table table1 ( col1 float(1), col2 float ) When I check the table definition using sp_help or script table as create, I get the float(1) as real CREATE TABLE [dbo].[table1]( [col1] [real] NULL, [col2] [float] NULL ) As per my understanding from msdn and stackoverflow references, float can have a precision n ranging from 1 to 53. Why is it getting converted to real by default whenever float has a precision specified? 回答1: SQL Server doesn't remember

Counting by Item & Channel by First Two Months Sold

只谈情不闲聊 提交于 2019-12-11 05:04:05
问题 Following up on my last question, Counting Items based on First Month Sold, I need to count items by the first two months they were sold but also need to group by channel along with item, along with total item qty sold as well. See sample code below DECLARE @sales table( itemnumber int, saledate date, channeltype varchar, ordid varchar, orditemqty int) INSERT INTO @sales VALUES(43029, '2011-26-03', Channel2, 1, 5) INSERT INTO @sales VALUES(43029, '2011-26-03', Channel2, 2, 6) INSERT INTO

Counting Items based on First Month Sold

浪尽此生 提交于 2019-12-11 05:03:36
问题 I have a list of orders, along with a list of items that were sold in each order. However, I only want to count items sold during the first month the items were for sale. This would typically be figured out by looking at the minimum date in which an item appeared. Below is some sample code DECLARE @sales table( itemnumber int, saledate date, ordid int) INSERT INTO @sales VALUES(43029, '2011-26-03', 1) INSERT INTO @sales VALUES(43029, '2011-26-03', 2) INSERT INTO @sales VALUES(43029, '2011-26

Handling very big table in SQL Server Performance

青春壹個敷衍的年華 提交于 2019-12-11 04:48:28
问题 I'm having some troubles to deal with a very big table in my database. Before to talk about the problem, let's talk about what i want to achieve. I have two source tables : Source 1: SALES_MAN (ID_SMAN, SM_LATITUDE, SM_LONGITUDE) Source 2: CLIENT (ID_CLIENT, CLATITUDE, CLONGITUDE) Target: DISTANCE (ID_SMAN, ID_CLIENT, SM_LATITUDE, SM_LONGITUDE, CLATITUDE, CLONGITUDE, DISTANCE) The idea is to find the top N nearest SALES_MAN for every client using a ROW_NUMBER in the target table. What I'm

Remote connection to SQL Server DB from WPF application

廉价感情. 提交于 2019-12-11 04:48:16
问题 Do I need to install SQL Server (Client tools) to a computer on which I am going to put one WPF application, which accesses SQL Server DB remotely? The PC will have fresh new Windows and I wonder is it enough for running the application just to install the appropriate .NET Framework and to configure the connection string (no installation of any SQL Server stuff). P.S. (DB - SQL Server Express 2016.) Let's say I've configured the server's DB and Firewall to accept remote access. Thanks. --

The data types date and datetime are incompatible in the add operator

六眼飞鱼酱① 提交于 2019-12-11 04:27:37
问题 I recently created in a SQL Server 2008 dev environment a function that concatenates a date and time like this select cast('2016-11-09 15:35:00' AS DATE) + CAST('00:00:00' AS DATETIME) In SQL Server 2008 it works well but deployed in SQL Server 2016 it throws an error The data types date and datetime are incompatible in the add operator. But it works well ONLY if queries are placed separately select cast('2016-11-09 15:35:00' AS DATE) select CAST('00:00:00' AS DATETIME) So, how can I fix this

SQL Server 2016: CREATE ASSEMBLY for assembly 'System.ServiceModel' failed

家住魔仙堡 提交于 2019-12-11 04:15:30
问题 I am trying to import System.ServiceModel.dll for one of my projects in getting the following: CREATE ASSEMBLY for assembly 'System.ServiceModel' failed because assembly 'microsoft.visualbasic.activities.compiler' is malformed or not a pure .NET assembly. SQL Server is running on Windows Server 2012 R2. Is there a fix for this issue? I am aware of similar issues with SQL Server 2012? How about SQL Server 2014? Thanks in advance 回答1: No, there is no fix that will allow for loading ServiceModel

Json pairs to rows

无人久伴 提交于 2019-12-11 04:13:43
问题 I am back on attacking SQL Server 2016 with JSON documents. I have had some luck through deep digging through the net, however I still cannot figure out how to turn my json results into rows with multiple value columns. I was looking to create something like this: +-----------+-------+------------+-----------+-------+------------------+---------+-----+-------+-------+---------+ | DateTime | Side | Identifier | Color | Level | SDSa | Current | LEF | Sys | Membr | SDS | +-----------+-------+---

Automatically Create Indexes in Different Filegroup, edit Publish Profile Script

ε祈祈猫儿з 提交于 2019-12-11 03:42:00
问题 I need a way to automatically move clustered indexes into one filegroup : ClusteredFilegroup, and all nonclustered indexes to a different filegroup NonClusteredFilegroup upon DDL creation . We have sql publish profile which creates similar script below every weekly deployment. How do I utilize powershell to conduct this? I would like to have powershell add words ON [ClusteredFilegroup] after every table creation or ON [NonClusteredFilegroup] for every nonclustered index. Powershell should be