sql-server-2014

SQL Server Management Studio can not connect

给你一囗甜甜゛ 提交于 2019-11-29 14:29:58
问题 I have installed SQL Server Management Studio 2014. In "connect to server" window, I selected server type as "Database engine", server name as "(local)" but when I try to connect, n error is shown- TITLE: Connect to Server Cannot connect to .. ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to

How to generate minute intervals between two dates in T-SQL?

白昼怎懂夜的黑 提交于 2019-11-29 13:08:12
I have a table of startTime and endTimes. I need to generate a table of intervals between those two dates in minutes. Here's some sample data: declare @intervalMinutes int = 10 declare @myDates table ( myId int primary key identity, startTime datetime, endTime datetime ) insert @myDates (startTime, EndTime) values ('2016-07-10 08:00','2016-07-10 09:00') insert @myDates (startTime, EndTime) values ('2016-07-12 10:00','2016-07-12 12:00') insert @myDates (startTime, EndTime) values ('2016-07-14 12:30','2016-07-14 14:30') What I'd like to see is for each myId a set of dates of interval

How to insert values into two tables with a foreign key relationship?

一曲冷凌霜 提交于 2019-11-29 09:45:39
问题 I created two tables: Table tblStaff with columns id (primary key, auto increment), name , age , address Table tblRoleOfStaff with columns id (primary key, auto increment), StaffId (foreign key to tblStaff ), RoleId I have form to create new staff with existing role. Data sample to insert: (name, age, address, roleId) = ('my name',20,'San Jose', 1) I want to write a stored procedure in SQL Server 2014 to insert new staff to tblStaff and insert new record into tbleRoleOfStaff with staffId I

Could not find server 'server name' in sys.servers. SQL Server 2014

天大地大妈咪最大 提交于 2019-11-29 09:35:31
I recently upgraded our SQL Server from 2005 to 2014 (linked server) and I am noticing that one of the stored procedures which calls the exec command to execute a stored procedure on the upgraded linked server is failing with the error Could not find server 'server name' in sys.servers.Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. The issue is that the linked server exists and I have done tests to ensure I can query the tables from the linked server. Here are the checks I did to see if the

SQL Server : Split string to row

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 08:43:30
How to turn data from below: CODE COMBINATION USER 1111.111.11.0 KEN; JIMMY 666.778.0.99 KEN 888.66.77.99 LIM(JIM); JIMMY To CODE COMBINATION USER 1111.111.11.0 KEN 1111.111.11.0 JIMMY 666.778.0.99 KEN 888.66.77.99 LIM(JIM) 888.66.77.99 JIMMY I know in SQL Server 2016 this can be done by split string function, but my production is SQL Server 2014. With this TVF, you can supply the string to be split and delimiter. Furthermore, you get the sequence number which can be very useful for secondary processing. Select [CODE COMBINATION] ,[USER] = B.RetVal From YourTable A Cross Apply [dbo].[udf-Str

In-Memory user defined table, not in memory?

醉酒当歌 提交于 2019-11-29 06:28:09
I am using SQL Server 2014 CTP2, with READ_COMMITTED_SNAPSHOT ON (I think it's important for the question). I have create an In-Memory table type (very similar to the example the technet blog, SQL Server 2014 In Memory OLTP: Memory-Optimized Table Types and Table Variables ), and I have several In-Memory tables. In the query itself I have a join between the regular In-Memory tables and the In-Memory table type, acting as a filter, when I execute the query I get this error message: "A query that accesses memory optimized tables using the READ COMMITTED isolation level, cannot access disk based

Incorrect syntax near 'THROW'

依然范特西╮ 提交于 2019-11-29 05:30:49
IF @SQL IS NOT NULL BEGIN BEGIN TRY EXEC sp_executesql @SQL PRINT 'SUCCESS: ' + @SQL END TRY BEGIN CATCH SET @ErrorMessage = N'Error dropping constraint' + @CRLF + 'Table ' + @TableName + @CRLF + 'Script: ' + @SQL + @CRLF + 'Error message: ' + ERROR_MESSAGE() + @CRLF THROW 50100, @ErrorMessage, 1; END CATCH END When the CATCH executes, I get the following error: Msg 102, Level 15, State 1, Line 257 Incorrect syntax near 'THROW'. Replacing THROW with PRINT @ErrorMessage works. Replacing @ErrorMessage variable with a literal string works. According to the docs, however, THROW is supposed to be

Cannot be opened because it is version 852. this server supports version 782 and earlier

落爺英雄遲暮 提交于 2019-11-29 04:02:51
I am using Visual Studio 2017 and SQL Server 2014. While attaching a database file to Visual Studio, I get this error: " " After upgrading the file I used this connection string <connectionStrings> <add name="con" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\binaaelmamorra.mdf;Integrated Security=True;Connect Timeout=30"/> </connectionStrings> It's working fine on my machine, but on the client machine, an error pops up saying Cannot be opened because it is version 852. This server supports version 782 and earlier Though I installed SQL Server 2016 local

Does the Poor Mans T-SQL formatting add-in for Management Studio 2012 work in Management Studio 2014?

穿精又带淫゛_ 提交于 2019-11-28 15:35:35
问题 Does the Poor Mans T-SQL formatting add-in for Management Studio 2012 work in Management Studio 2014? In SSMS 2012, if I go to tools, it showed up in the list. In SSMS 2014, it doesn't. I tried to run the installer again, and it gave me options to repair or uninstall. I had the formatter installed prior to installing 2014. EDIT: The tool is available here. 回答1: Create the folder %SystemDrive%\ProgramData\Microsoft\SQL Server Management Studio\12.0\Addins\ if it does not exist. Then just copy

T-SQL incrementing counter based on change in a column value

无人久伴 提交于 2019-11-28 13:11:17
I have sample table like below. The table is sorted by another column that is not shown. I need to increment a counter column value based on whenever there is change in the value column. Please see below for an example. How can this be done in T-SQL (SQL Server 2014). ID Value 1 3 2 3 3 2 4 2 5 2 6 3 7 0 8 0 Expected Output: ID Value Counter 1 3 1 2 3 1 3 2 2 4 2 2 5 2 2 6 3 3 7 0 4 8 0 4 In SQL Server 2012 and later, you have the luxury of 1) analytic functions, and 2) running totals: declare @t table ( Id int primary key, Value int not null ); insert into @t (Id, Value) values (1, 3), (2, 3)