sql-server-2012

Using OPENQUERY (exec stored procedure) to create new temporary table fails with error 11526

拈花ヽ惹草 提交于 2019-12-17 16:46:18
问题 I have SQL Server 2012 full version installed on my development PC. I am trying to follow the examples here, which show how to create a new temporary table using a stored procedure as the source of the data. I am trying to combine the results of several stored procedures into a single temporary table (the column-structure/definition of the various resultsets is identical). To test if the plumbing is working, I issue this query: SELECT * FROM OPENQUERY("FOO\SQL2012", 'exec mySchema

Use RAND() in User Defined Function

杀马特。学长 韩版系。学妹 提交于 2019-12-17 16:28:37
问题 I am trying to create a user defined function which calls the system RAND() function inside it, when I try to create the function it errors out with the following message: Msg 443, Level 16, State 1, Procedure getNumber, Line 10 Invalid use of a side-effecting operator 'rand' within a function. My function code: CREATE FUNCTION getNumber(@_id int) RETURNS DECIMAL(18,4) AS BEGIN DECLARE @RtnValue DECIMAL(18,4); SELECT TOP 1 @RtnValue = EmployeeID FROM dbo.Employees ORDER BY EmployeeID DESC SET

Possible to restore a backup of SQL Server 2014 on SQL Server 2012?

你离开我真会死。 提交于 2019-12-17 16:00:57
问题 I know that you can't (at least not easily) restore a SQL Server 2012 backup on SQL Server 2008. But how does it work for SQL Server 2014 to SQL Server 2012 ? On database level there is the property to adjust the compatibility mode to any other SQL Server version. How does this helps or work ? Will it only disallow the features from 2014? To be honest I already tried to restore a backup, but 2012 didn't recognize the datafile, so I couldn't click ok Button to start the restore procedure. Did

Get previous and next row from rows selected with (WHERE) conditions

a 夏天 提交于 2019-12-17 15:43:21
问题 For example I have this statement: my name is Joseph and my father's name is Brian This statement is splitted by word, like this table: ------------------------------ | ID | word | ------------------------------ | 1 | my | | 2 | name | | 3 | is | | 4 | Joseph | | 5 | and | | 6 | my | | 7 | father's | | 8 | name | | 9 | is | | 10 | Brian | ------------------------------ I want to get previous and next word of each word For example I want to get previous and next word of "name": ---------------

SQL Server equivalent of substring_index function in MySQL

廉价感情. 提交于 2019-12-17 14:01:59
问题 I am trying to port a query from MySQL to SQL SERVER 2012. How do i write an equivalent for MySQL's substring_index()? MySQL SUBSTRING_INDEX() returns the substring from the given string before a specified number of occurrences of a delimiter. SUBSTRING_INDEX(str, delim, count) SELECT SUBSTRING_INDEX('www.somewebsite.com','.',2); Output: 'www.somewebsite' 回答1: Try this solution based on T-SQL and XQuery( (root/row)[position() <= sql:variable("@count")] ): T-SQL Scalar function: CREATE

SSIS Package Not Running as 32bit in SQL Server 2012

百般思念 提交于 2019-12-17 13:59:46
问题 I have a package that I developed in VS2012 (using the SQL Data Tools component) which collects data from a DBF file using the VFPOLEDB provider, and puts it into a database on a SQL Server 2012 X64 server. The project containing the package has the DebugOption of Run64BitRuntime set to false. I have imported this package to the SSIS Package Store of a test and live server (identical setups). The VFPOLEDB provider is installed on both, and I can see in the registry of both machines that it's

Index was outside the bounds of the Array. (Microsoft.SqlServer.smo)

北城以北 提交于 2019-12-17 10:46:58
问题 I am using SQL Server 2008 R2 . It is working fine. But recently, I have changed my hosting server and I came to know that they have installed SQL Server 2012 on Server. Now, Issue is that after connecting with Server Database through SQL Server 2008 R2 , When I click on any table name or Stored Procedure, I am getting error : Index was outside the bounds of the array. (Microsoft.SqlServer.smo) So, is there any issue from my side or It is from Server Side ??? and How can I prevent this issue

How to enable bulk permission in SQL Server

无人久伴 提交于 2019-12-17 07:25:23
问题 I am trying to insert images using "bulk" into SQL Server 2012. But, am ending up with the error message stating tha: Msg 4834, Level 16, State 1, Line 2 You do not have permission to use the bulk load statement. I have "sysadmin" access. 回答1: Try GRANT ADMINISTER BULK OPERATIONS TO [server_login] . It is a server level permission, not a database level. This has fixed a similar issue for me in that past (using OPENROWSET I believe). 回答2: USE master go GRANT ADMINISTER BULK OPERATIONS TO shira

How to get next value of SQL Server sequence in Entity Framework?

跟風遠走 提交于 2019-12-17 07:24:00
问题 I want to make use SQL Server sequence objects in Entity Framework to show number sequence before save it into database. In current scenario I'm doing something related by increment by one in stored procedure (previous value stored in one table) and passing that value to C# code. To achieve this I needed one table but now I want to convert it to a sequence object (will it give any advantage ?). I know how to create sequence and get next value in SQL Server. But I want to know how to get next

Adding a query hint when calling Table-Valued Function

雨燕双飞 提交于 2019-12-17 04:55:22
问题 I'm calling a Table-Valued Function from entity framework and need to be able to add the option (recompile) to it because the execution plan it picks up is not optimal. Running the query in SQL Server Management Studio, it would look something like this: select * from dbo.fDE_myquery(0, 0, 3309, '7/1/2013', '7/1/2014', 0, 0) option (recompile) By from EF, there's no way to add that hint, AFAIK. The EF part looks something like: var query = from f in ctx.fDE_myQuery(aBool, anotherBool,