sql-server-2014

Columns with data-type prefix cause “Type X is not a defined system type” error

好久不见. 提交于 2019-12-24 20:28:17
问题 I'm working with a 3rd party database. Usually queries that I write in LINQPad and later translate to Entity Framework Core (2.1) work without any issues. However, not this time. When I try to use the column Status I'm getting the following SqlException : Class 16 byte LineNumber 1 int Message "Type Enumeration is not a defined system type." string Number 243 int Procedure "" string Server "..." string Source ".Net SqlClient Data Provider" string State 2 byte so I opend the SQL Server

bug in ISNUMERIC function?

為{幸葍}努か 提交于 2019-12-24 17:43:19
问题 I have a problem with ISNUMERIC Function in SQL-server. I have a table, which contains one column with nvarchar type. In this column I have such a values 123 , 241 , ... and sometimes string values like LK My Query: WITH CTE AS ( SELECT * FROM MyTable WHERE ISNUMERIC([Column1]) = 1 ) SELECT * FROM CTE WHERE CAST(cte.Column1 AS INT) > 8000 but this query returns this error message: error converting data type nvarchar 'LK' to int my expectation is, that the Common table expression filter all

Firewall rules to allow remote connection to SQL Server in a different domain

喜欢而已 提交于 2019-12-24 17:25:45
问题 I recently installed SQL Server Express 2014 on a series of machines running Windows Server 2012. Seven machines in total. All but 1 of them live in the same local domain company.local . A single rogue machine lives in a different public domain public.company.org . The installation process on this machine on a separate domain was carried out by someone who was not paying much attention to the process and pretty much selected all defaults (a.k.a. a click-click-click installation.) As such,

SQL - Get specific element from an array

不问归期 提交于 2019-12-24 12:27:37
问题 Suppose I have 2 variables that look like an array: declare @code nvarchar(200) = ',10501,10203,10491,10490,10091,10253,10008,10020,10570,10499,'; declare @value nvarchar(200) = 'True~~100000006~Digital~0~0~~1388.76~Completed~True'; I need to find if @code contains 10490 (for example) and if it does, I need to find a corresponding value (by its index) in @value variable which would be Digital since 10490 is the 4th element in @code array and 4th element of @value array is Digital (note that

SQL Server to count how many times a value appears between multiple date ranges and compare to previous weeks

久未见 提交于 2019-12-24 09:48:43
问题 I first asked a similar question at SQL Server to count how many times a value appears between multiple date ranges and wasn't sure if I should post a new question or modify the original post. Though it's building on the original post I felt it was different enough to render a new post - please advise if this was the correct thing to do. I wasn't given a few solutions that worked well but unfortunately a caveat was thrown at me and I need to make some modifications based on an additional

Performing a running subtraction in T-SQL

醉酒当歌 提交于 2019-12-24 08:59:06
问题 I'm sitting with two tables (although they're temp-tables) looking like this: CREATE TABLE [dbo].[Invoice] ( [InvoiceId] [int] NOT NULL, [ReceiverId] [int] NOT NULL, [Amount] [numeric](19, 2) NOT NULL, [Priority] [int] NOT NULL ); GO CREATE TABLE [dbo].[Payment] ( [PaymentId] [int] NOT NULL, [SenderId] [int] NOT NULL, [Amount] [numeric](19, 2) NOT NULL ); GO The data could look something like this: Invoice InvoiceId ReceiverId Amount Priority 1 1 100.00 1 2 1 100.00 2 3 2 100.00 1 4 2 100.00

Why does this CTE act like a counter?

喜欢而已 提交于 2019-12-24 07:47:37
问题 The behaviour of the following query is different from my understanding of CTE, can someone elaborate why this is so? with cte (n) as ( select 1 union all select n + 1 from cte where n<10 ) select * from cte I'm expecting the following output: 1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10 But I'm getting: 1,2,3,4,5,6,7,8,9,10 Why? 回答1: A CTE is basically a re-usable sub-query that can refer to itself, so your final query is equivalent to: SELECT 1 UNION ALL (SELECT 2 UNION ALL (SELECT 3 ... Until n

NCache as Entity Framework second level cache not syncing with database

笑着哭i 提交于 2019-12-24 05:55:20
问题 Using NCache 4.6 as EF 6.1.3 second level cache, SqlDependency is not working. (It cant detect changes that I make directly in SQL server. Also does not update cache or invalidate it when using EF to add or delete entities to database. Albeit it detect updating an entity) I've installed NCache in my computer with IP: 192.168.56.1 and SQL server 2014 in vbox with IP: 192.168.56.101 using instruction from their site and customizing them to meet my IP & user, I executed following SQL: ALTER

How to return value based on the last available timestamp if the exact time is unavailable?

大兔子大兔子 提交于 2019-12-24 04:07:09
问题 I am trying to return data in fifteen minute intervals. The first thing I thought to do was this: select * from myTable where DATEPART(minute, Timestamp) % 15 = 0 But there are two problems with this approach. The first is that there will not necessarily always be data with a timestamp at a given minute, the other is that sometimes there are multiple data points at a given minute with different second values. I want to have exactly one row for each fifteen minute group, at :00, :15, :30, etc.

Connecting to local SQL Server instance

荒凉一梦 提交于 2019-12-24 03:07:59
问题 I'm attempting to connect to a local instance of SQL Server running on my machine. I am able to connect to a local instance with this code from our server, but it fails on my local machine. I've enabled named pipes and all the ips in the SQL Server configuration. The code I'm using is as follows: from pymssql import connect server = r'.\SQLEXPRESS2014' # I've also tried MORGANT-PC\SQLEXPRESS and SQLEXPRESS2014 username = 'MyUserName' password = 'MyPassword' master_database_name =